EmbeddedRelated.com
Forums

CAN Bus - Baud rate problems with LPC2129 (I'm not sure...)

Started by Thiago Lima March 15, 2007
Hello all LPC2000 friends,

I'm developing an eletronic system using LPC2129 with a 12 MHz
crystal. I configured it to operate in 48 MHz and PCLK of 12 MHz ( 48
MHz / 4 ).

At this moment I'm trying to make my LPC2129 communicate with another
electronic system, configured to operate in a CAN network
communicating in 125 kbps. This system that needs to communicate with
my system is also being developed and the source code were all did
using loop back mode of this CAN controller (Not Philips).

I'm writing this e-mail to ask to you if my CAN baud rate
configuration on LPC2129 is OK for communication in 125kbps.
The parameters are:

TSEG1_7TQ ( 6 << 16 )
TSEG2_6TQ ( 5 << 20 )
BRP ( 5 << 0 )
SJW_1TQ ( 1 << 14 )
SPL_3X ( 1 << 23 )
#define CanBitRate125k_12MHz (BRP | SJW_1TQ | TSEG1_7TQ | TSEG2_6TQ | SPL_3X)

I did the following division in order to find this parameters:
Baudrate PCLK
= -------------------------------
(BRP+1) ((TSEG1+1)+(TSEG2+1)+3)

125000 12000000
= --------------------
(5+1) ((6+1)+(5+1)+3)
Is this calculus correct for 12MHz and 125 Kbps (I think it is - but
I'm not so sure...).

I developed the source code to send and receive data on CAN bus, being
helped, of course, by the excellent tutorials, app notes and routines
found on the internet. Using 2 can nodes with the same source code,
both with resistor of 120 ohms between RXD and TXD, and both with
LPC2129 as the CAN controller, it worked!!! I could see data being
delivered and received, using the UART as debug tool.

If I connect the oscilloscope on this bus, could I see the waveforms
of CAN being transmited/received, on the bus?

I know I configured one valid baud rate and I'm trafegating data on
the bus, to one LPC2129 to other...
But it does not communicate with the other node, not a LPC and not a
Philips component (with different equation for baud rate calculation).
This Can Controller chip could feel that one CAN node is on the bus,
because the error when trying to send a data on the bus (Transmission
Error - seems to be baud rate error, am I right?) is different when I
disconnect LPC from the microchip chip (Bus Off error when
disconnect).

I would appreciate you giving me any help / hint, because I really
don't know what to do. What are the best flags that I have to monitor
on the LPC2129 in order to get more information about this [ no
communication - baud ] error?
Thiago
Electrical Engineer

An Engineer's Guide to the LPC2100 Series

Hi Thiago,

How did you decide on TSEG1 and TSEG2 values as at a glance they don't
appear to give 16 clock cycles per bit?
If I remember correctly the delay from the sync point to the sample point is
TSEG1 + 1, and the delay from the sample point to the next sync point is the
value in TSEG2 + TSEG1 + 3.
Given that the default settings for can give 16 cycles per bit I'd have
expected TSEG2 + TSEG1 + 3 = 16. Yours appears to sum to 14, so are you
sure that the device at the other end is set up the same way?
I would have thought the default values for these would have been fine?
(TSEG1 = 0xC, TSEG2 = 0x1, SJW = 0x0).
Your BRP of 5 is correct for 16 cycles per bit at 125K transmission speed on
a 12Meg Clock.

In short what does trying:
TSEG1: (0xC << 16)
TSEG2: (0x1 << 20)
BRP: (0x5 << 0)
SJW: (0 << 14)
SPL_3X: (1 << 23)

ie: C1BTR = 0x009C0005

give you?

Andy

-----Original Message-----
From: l... [mailto:l...]On Behalf Of
Thiago Lima
Sent: 15 March 2007 03:28
To: l...
Subject: [lpc2000] CAN Bus - Baud rate problems with LPC2129 (I'm not
sure...)
Hello all LPC2000 friends,

I'm developing an eletronic system using LPC2129 with a 12 MHz
crystal. I configured it to operate in 48 MHz and PCLK of 12 MHz ( 48
MHz / 4 ).

At this moment I'm trying to make my LPC2129 communicate with another
electronic system, configured to operate in a CAN network
communicating in 125 kbps. This system that needs to communicate with
my system is also being developed and the source code were all did
using loop back mode of this CAN controller (Not Philips).

I'm writing this e-mail to ask to you if my CAN baud rate
configuration on LPC2129 is OK for communication in 125kbps.
The parameters are:

TSEG1_7TQ ( 6 << 16 )
TSEG2_6TQ ( 5 << 20 )
BRP ( 5 << 0 )
SJW_1TQ ( 1 << 14 )
SPL_3X ( 1 << 23 )

#define CanBitRate125k_12MHz (BRP | SJW_1TQ | TSEG1_7TQ | TSEG2_6TQ |
SPL_3X)

I did the following division in order to find this parameters:

Baudrate PCLK
= -------------------------------
(BRP+1) ((TSEG1+1)+(TSEG2+1)+3)

125000 12000000
= --------------------
(5+1) ((6+1)+(5+1)+3)

Is this calculus correct for 12MHz and 125 Kbps (I think it is - but
I'm not so sure...).

I developed the source code to send and receive data on CAN bus, being
helped, of course, by the excellent tutorials, app notes and routines
found on the internet. Using 2 can nodes with the same source code,
both with resistor of 120 ohms between RXD and TXD, and both with
LPC2129 as the CAN controller, it worked!!! I could see data being
delivered and received, using the UART as debug tool.

If I connect the oscilloscope on this bus, could I see the waveforms
of CAN being transmited/received, on the bus?

I know I configured one valid baud rate and I'm trafegating data on
the bus, to one LPC2129 to other...
But it does not communicate with the other node, not a LPC and not a
Philips component (with different equation for baud rate calculation).
This Can Controller chip could feel that one CAN node is on the bus,
because the error when trying to send a data on the bus (Transmission
Error - seems to be baud rate error, am I right?) is different when I
disconnect LPC from the microchip chip (Bus Off error when
disconnect).

I would appreciate you giving me any help / hint, because I really
don't know what to do. What are the best flags that I have to monitor
on the LPC2129 in order to get more information about this [ no
communication - baud ] error?

Thiago
Electrical Engineer
Thanks Andy for the help.

If I try to use the following values:

TSEG1: (0x7 << 16)
TSEG2: (0x6 << 20)
BRP: (0x5 << 0)
SJW: (0 << 14)
SPL_3X: (1 << 23)

TSEG2 + TSEG1 + 3 = 16

Is it ok for 12 MHz, 125 kbps?

Baudrate PCLK
= -------------------------------
(BRP+1) ((TSEG1)+(TSEG2)+3)

125000 12000000
= --------------------
(5+1) ((7)+(6)+3)
Thank you in advance...

--- In l..., "Andrew Berney" wrote:
>
> Hi Thiago,
>
> How did you decide on TSEG1 and TSEG2 values as at a glance they
don't
> appear to give 16 clock cycles per bit?
> If I remember correctly the delay from the sync point to the sample
point is
> TSEG1 + 1, and the delay from the sample point to the next sync
point is the
> value in TSEG2 + TSEG1 + 3.
> Given that the default settings for can give 16 cycles per bit I'd
have
> expected TSEG2 + TSEG1 + 3 = 16. Yours appears to sum to 14, so
are you
> sure that the device at the other end is set up the same way?
> I would have thought the default values for these would have been
fine?
> (TSEG1 = 0xC, TSEG2 = 0x1, SJW = 0x0).
> Your BRP of 5 is correct for 16 cycles per bit at 125K transmission
speed on
> a 12Meg Clock.
>
> In short what does trying:
> TSEG1: (0xC << 16)
> TSEG2: (0x1 << 20)
> BRP: (0x5 << 0)
> SJW: (0 << 14)
> SPL_3X: (1 << 23)
>
> ie: C1BTR = 0x009C0005
>
> give you?
>
> Andy
>
> -----Original Message-----
> From: l... [mailto:l...]On
Behalf Of
> Thiago Lima
> Sent: 15 March 2007 03:28
> To: l...
> Subject: [lpc2000] CAN Bus - Baud rate problems with LPC2129 (I'm
not
> sure...)
> Hello all LPC2000 friends,
>
> I'm developing an eletronic system using LPC2129 with a 12 MHz
> crystal. I configured it to operate in 48 MHz and PCLK of 12 MHz
( 48
> MHz / 4 ).
>
> At this moment I'm trying to make my LPC2129 communicate with
another
> electronic system, configured to operate in a CAN network
> communicating in 125 kbps. This system that needs to communicate
with
> my system is also being developed and the source code were all did
> using loop back mode of this CAN controller (Not Philips).
>
> I'm writing this e-mail to ask to you if my CAN baud rate
> configuration on LPC2129 is OK for communication in 125kbps.
> The parameters are:
>
> TSEG1_7TQ ( 6 << 16 )
> TSEG2_6TQ ( 5 << 20 )
> BRP ( 5 << 0 )
> SJW_1TQ ( 1 << 14 )
> SPL_3X ( 1 << 23 )
>
> #define CanBitRate125k_12MHz (BRP | SJW_1TQ | TSEG1_7TQ |
TSEG2_6TQ |
> SPL_3X)
>
> I did the following division in order to find this parameters:
>
> Baudrate PCLK
> = -------------------------------
> (BRP+1) ((TSEG1+1)+(TSEG2+1)+3)
>
> 125000 12000000
> = --------------------
> (5+1) ((6+1)+(5+1)+3)
>
> Is this calculus correct for 12MHz and 125 Kbps (I think it is -
but
> I'm not so sure...).
>
> I developed the source code to send and receive data on CAN bus,
being
> helped, of course, by the excellent tutorials, app notes and
routines
> found on the internet. Using 2 can nodes with the same source
code,
> both with resistor of 120 ohms between RXD and TXD, and both with
> LPC2129 as the CAN controller, it worked!!! I could see data being
> delivered and received, using the UART as debug tool.
>
> If I connect the oscilloscope on this bus, could I see the
waveforms
> of CAN being transmited/received, on the bus?
>
> I know I configured one valid baud rate and I'm trafegating data
on
> the bus, to one LPC2129 to other...
> But it does not communicate with the other node, not a LPC and
not a
> Philips component (with different equation for baud rate
calculation).
> This Can Controller chip could feel that one CAN node is on the
bus,
> because the error when trying to send a data on the bus
(Transmission
> Error - seems to be baud rate error, am I right?) is different
when I
> disconnect LPC from the microchip chip (Bus Off error when
> disconnect).
>
> I would appreciate you giving me any help / hint, because I really
> don't know what to do. What are the best flags that I have to
monitor
> on the LPC2129 in order to get more information about this [ no
> communication - baud ] error?
>
> Thiago
> Electrical Engineer
>
>
>
Hi Thiago,

those values should give you the correct bit rate yes, with TSEG1 and 2
you're now simply changing when the sample period is conducted over the 16
clk cycle. If it's still not working you might be better off posting the
info you've got for the device at the other end of the can bus. Hope you get
it working :)

Andy

-----Original Message-----
From: l... [mailto:l...]On Behalf Of
tpfslima
Sent: 15 March 2007 14:40
To: l...
Subject: [lpc2000] Re: CAN Bus - Baud rate problems with LPC2129 (I'm not
sure...)
Thanks Andy for the help.

If I try to use the following values:

TSEG1: (0x7 << 16)
TSEG2: (0x6 << 20)
BRP: (0x5 << 0)
SJW: (0 << 14)
SPL_3X: (1 << 23)

TSEG2 + TSEG1 + 3 = 16

Is it ok for 12 MHz, 125 kbps?

Baudrate PCLK
= -------------------------------
(BRP+1) ((TSEG1)+(TSEG2)+3)

125000 12000000
= --------------------
(5+1) ((7)+(6)+3)

Thank you in advance...

--- In l..., "Andrew Berney" wrote:
>
> Hi Thiago,
>
> How did you decide on TSEG1 and TSEG2 values as at a glance they
don't
> appear to give 16 clock cycles per bit?
> If I remember correctly the delay from the sync point to the sample
point is
> TSEG1 + 1, and the delay from the sample point to the next sync
point is the
> value in TSEG2 + TSEG1 + 3.
> Given that the default settings for can give 16 cycles per bit I'd
have
> expected TSEG2 + TSEG1 + 3 = 16. Yours appears to sum to 14, so
are you
> sure that the device at the other end is set up the same way?
> I would have thought the default values for these would have been
fine?
> (TSEG1 = 0xC, TSEG2 = 0x1, SJW = 0x0).
> Your BRP of 5 is correct for 16 cycles per bit at 125K transmission
speed on
> a 12Meg Clock.
>
> In short what does trying:
> TSEG1: (0xC << 16)
> TSEG2: (0x1 << 20)
> BRP: (0x5 << 0)
> SJW: (0 << 14)
> SPL_3X: (1 << 23)
>
> ie: C1BTR = 0x009C0005
>
> give you?
>
> Andy
>
> -----Original Message-----
> From: l... [mailto:l...]On
Behalf Of
> Thiago Lima
> Sent: 15 March 2007 03:28
> To: l...
> Subject: [lpc2000] CAN Bus - Baud rate problems with LPC2129 (I'm
not
> sure...)
>
>
> Hello all LPC2000 friends,
>
> I'm developing an eletronic system using LPC2129 with a 12 MHz
> crystal. I configured it to operate in 48 MHz and PCLK of 12 MHz
( 48
> MHz / 4 ).
>
> At this moment I'm trying to make my LPC2129 communicate with
another
> electronic system, configured to operate in a CAN network
> communicating in 125 kbps. This system that needs to communicate
with
> my system is also being developed and the source code were all did
> using loop back mode of this CAN controller (Not Philips).
>
> I'm writing this e-mail to ask to you if my CAN baud rate
> configuration on LPC2129 is OK for communication in 125kbps.
> The parameters are:
>
> TSEG1_7TQ ( 6 << 16 )
> TSEG2_6TQ ( 5 << 20 )
> BRP ( 5 << 0 )
> SJW_1TQ ( 1 << 14 )
> SPL_3X ( 1 << 23 )
>
> #define CanBitRate125k_12MHz (BRP | SJW_1TQ | TSEG1_7TQ |
TSEG2_6TQ |
> SPL_3X)
>
> I did the following division in order to find this parameters:
>
> Baudrate PCLK
> = -------------------------------
> (BRP+1) ((TSEG1+1)+(TSEG2+1)+3)
>
> 125000 12000000
> = --------------------
> (5+1) ((6+1)+(5+1)+3)
>
> Is this calculus correct for 12MHz and 125 Kbps (I think it is -
but
> I'm not so sure...).
>
> I developed the source code to send and receive data on CAN bus,
being
> helped, of course, by the excellent tutorials, app notes and
routines
> found on the internet. Using 2 can nodes with the same source
code,
> both with resistor of 120 ohms between RXD and TXD, and both with
> LPC2129 as the CAN controller, it worked!!! I could see data being
> delivered and received, using the UART as debug tool.
>
> If I connect the oscilloscope on this bus, could I see the
waveforms
> of CAN being transmited/received, on the bus?
>
> I know I configured one valid baud rate and I'm trafegating data
on
> the bus, to one LPC2129 to other...
> But it does not communicate with the other node, not a LPC and
not a
> Philips component (with different equation for baud rate
calculation).
> This Can Controller chip could feel that one CAN node is on the
bus,
> because the error when trying to send a data on the bus
(Transmission
> Error - seems to be baud rate error, am I right?) is different
when I
> disconnect LPC from the microchip chip (Bus Off error when
> disconnect).
>
> I would appreciate you giving me any help / hint, because I really
> don't know what to do. What are the best flags that I have to
monitor
> on the LPC2129 in order to get more information about this [ no
> communication - baud ] error?
>
> Thiago
> Electrical Engineer
>
>
>
>
>
>
>
Andy,

Thanks for the informations.
You can see the other part of the problem on this link, if you want:
http://forum.microchip.com/tm.aspx?m#7289 .

I will try to make it work - make my can bus communicate on 125 kbs.
I give you feedback of what problems I found.
Thiago.

--- In l..., "Andrew Berney" wrote:
>
> Hi Thiago,
>
> those values should give you the correct bit rate yes, with TSEG1
and 2
> you're now simply changing when the sample period is conducted over
the 16
> clk cycle. If it's still not working you might be better off
posting the
> info you've got for the device at the other end of the can bus.
Hope you get
> it working :)
>
> Andy
>
> -----Original Message-----
> From: l... [mailto:l...]On
Behalf Of
> tpfslima
> Sent: 15 March 2007 14:40
> To: l...
> Subject: [lpc2000] Re: CAN Bus - Baud rate problems with LPC2129
(I'm not
> sure...)
> Thanks Andy for the help.
>
> If I try to use the following values:
>
> TSEG1: (0x7 << 16)
> TSEG2: (0x6 << 20)
> BRP: (0x5 << 0)
> SJW: (0 << 14)
> SPL_3X: (1 << 23)
>
> TSEG2 + TSEG1 + 3 = 16
>
> Is it ok for 12 MHz, 125 kbps?
>
> Baudrate PCLK
> = -------------------------------
> (BRP+1) ((TSEG1)+(TSEG2)+3)
>
> 125000 12000000
> = --------------------
> (5+1) ((7)+(6)+3)
>
> Thank you in advance...
>
> --- In l..., "Andrew Berney" wrote:
> >
> > Hi Thiago,
> >
> > How did you decide on TSEG1 and TSEG2 values as at a glance they
> don't
> > appear to give 16 clock cycles per bit?
> > If I remember correctly the delay from the sync point to the
sample
> point is
> > TSEG1 + 1, and the delay from the sample point to the next sync
> point is the
> > value in TSEG2 + TSEG1 + 3.
> > Given that the default settings for can give 16 cycles per bit
I'd
> have
> > expected TSEG2 + TSEG1 + 3 = 16. Yours appears to sum to 14, so
> are you
> > sure that the device at the other end is set up the same way?
> > I would have thought the default values for these would have
been
> fine?
> > (TSEG1 = 0xC, TSEG2 = 0x1, SJW = 0x0).
> > Your BRP of 5 is correct for 16 cycles per bit at 125K
transmission
> speed on
> > a 12Meg Clock.
> >
> > In short what does trying:
> > TSEG1: (0xC << 16)
> > TSEG2: (0x1 << 20)
> > BRP: (0x5 << 0)
> > SJW: (0 << 14)
> > SPL_3X: (1 << 23)
> >
> > ie: C1BTR = 0x009C0005
> >
> > give you?
> >
> > Andy
> >
> > -----Original Message-----
> > From: l... [mailto:l...]On
> Behalf Of
> > Thiago Lima
> > Sent: 15 March 2007 03:28
> > To: l...
> > Subject: [lpc2000] CAN Bus - Baud rate problems with LPC2129
(I'm
> not
> > sure...)
> >
> >
> > Hello all LPC2000 friends,
> >
> > I'm developing an eletronic system using LPC2129 with a 12 MHz
> > crystal. I configured it to operate in 48 MHz and PCLK of 12 MHz
> ( 48
> > MHz / 4 ).
> >
> > At this moment I'm trying to make my LPC2129 communicate with
> another
> > electronic system, configured to operate in a CAN network
> > communicating in 125 kbps. This system that needs to communicate
> with
> > my system is also being developed and the source code were all
did
> > using loop back mode of this CAN controller (Not Philips).
> >
> > I'm writing this e-mail to ask to you if my CAN baud rate
> > configuration on LPC2129 is OK for communication in 125kbps.
> > The parameters are:
> >
> > TSEG1_7TQ ( 6 << 16 )
> > TSEG2_6TQ ( 5 << 20 )
> > BRP ( 5 << 0 )
> > SJW_1TQ ( 1 << 14 )
> > SPL_3X ( 1 << 23 )
> >
> > #define CanBitRate125k_12MHz (BRP | SJW_1TQ | TSEG1_7TQ |
> TSEG2_6TQ |
> > SPL_3X)
> >
> > I did the following division in order to find this parameters:
> >
> > Baudrate PCLK
> > = -------------------------------
> > (BRP+1) ((TSEG1+1)+(TSEG2+1)+3)
> >
> > 125000 12000000
> > = --------------------
> > (5+1) ((6+1)+(5+1)+3)
> >
> > Is this calculus correct for 12MHz and 125 Kbps (I think it is -
> but
> > I'm not so sure...).
> >
> > I developed the source code to send and receive data on CAN bus,
> being
> > helped, of course, by the excellent tutorials, app notes and
> routines
> > found on the internet. Using 2 can nodes with the same source
> code,
> > both with resistor of 120 ohms between RXD and TXD, and both
with
> > LPC2129 as the CAN controller, it worked!!! I could see data
being
> > delivered and received, using the UART as debug tool.
> >
> > If I connect the oscilloscope on this bus, could I see the
> waveforms
> > of CAN being transmited/received, on the bus?
> >
> > I know I configured one valid baud rate and I'm trafegating data
> on
> > the bus, to one LPC2129 to other...
> > But it does not communicate with the other node, not a LPC and
> not a
> > Philips component (with different equation for baud rate
> calculation).
> > This Can Controller chip could feel that one CAN node is on the
> bus,
> > because the error when trying to send a data on the bus
> (Transmission
> > Error - seems to be baud rate error, am I right?) is different
> when I
> > disconnect LPC from the microchip chip (Bus Off error when
> > disconnect).
> >
> > I would appreciate you giving me any help / hint, because I
really
> > don't know what to do. What are the best flags that I have to
> monitor
> > on the LPC2129 in order to get more information about this [ no
> > communication - baud ] error?
> >
> > Thiago
> > Electrical Engineer
> >
> >
> >
> >
> >
> >
> >
>
>
Hi Thiago,

I had a chance to have a quick look at the chip you're using at the other
end and think I can probably now see where you're having a problem:
I think you have an error in the MCP2515 defines - SJW is currently set to
0x40 (2TQ) which sums your bit period to 17TQ in total not 16TQ.
Your MCP2515 defines should therefore read:
#define CAN_125kbps 2
#define SJW_1TQ 0x0
#define BTLMODE_CNF3 0x80
#define PHSEG1_7TQ 0x30
#define PRSEG_2TQ 0x01
#define PHSEG2_6TQ 0x05
#define SMPL_3X 0x40
#define WAKFIL_DISABLED 0x00

and the LPC equivalents as best I can see would then be:
#define TSEG1 (0x8 << 16)
#define TSEG2: (0x5 << 20)
#define BRP: (0x5 << 0)
#define SJW: (0x1 << 14)
#define SPL_3X: (0x1 << 23)

let me know if that gets it talking :)

Andy

-----Original Message-----
From: l... [mailto:l...]On Behalf Of
tpfslima
Sent: 15 March 2007 16:03
To: l...
Subject: [lpc2000] Re: CAN Bus - Baud rate problems with LPC2129 (I'm not
sure...)
Andy,

Thanks for the informations.
You can see the other part of the problem on this link, if you want:
http://forum.microchip.com/tm.aspx?m#7289 .

I will try to make it work - make my can bus communicate on 125 kbs.
I give you feedback of what problems I found.
Thiago.

--- In l..., "Andrew Berney" wrote:
>
> Hi Thiago,
>
> those values should give you the correct bit rate yes, with TSEG1
and 2
> you're now simply changing when the sample period is conducted over
the 16
> clk cycle. If it's still not working you might be better off
posting the
> info you've got for the device at the other end of the can bus.
Hope you get
> it working :)
>
> Andy
>
>
>
> -----Original Message-----
> From: l... [mailto:l...]On
Behalf Of
> tpfslima
> Sent: 15 March 2007 14:40
> To: l...
> Subject: [lpc2000] Re: CAN Bus - Baud rate problems with LPC2129
(I'm not
> sure...)
>
>
> Thanks Andy for the help.
>
> If I try to use the following values:
>
> TSEG1: (0x7 << 16)
> TSEG2: (0x6 << 20)
> BRP: (0x5 << 0)
> SJW: (0 << 14)
> SPL_3X: (1 << 23)
>
> TSEG2 + TSEG1 + 3 = 16
>
> Is it ok for 12 MHz, 125 kbps?
>
> Baudrate PCLK
> = -------------------------------
> (BRP+1) ((TSEG1)+(TSEG2)+3)
>
> 125000 12000000
> = --------------------
> (5+1) ((7)+(6)+3)
>
> Thank you in advance...
>
> --- In l..., "Andrew Berney" wrote:
> >
> > Hi Thiago,
> >
> > How did you decide on TSEG1 and TSEG2 values as at a glance they
> don't
> > appear to give 16 clock cycles per bit?
> > If I remember correctly the delay from the sync point to the
sample
> point is
> > TSEG1 + 1, and the delay from the sample point to the next sync
> point is the
> > value in TSEG2 + TSEG1 + 3.
> > Given that the default settings for can give 16 cycles per bit
I'd
> have
> > expected TSEG2 + TSEG1 + 3 = 16. Yours appears to sum to 14, so
> are you
> > sure that the device at the other end is set up the same way?
> > I would have thought the default values for these would have
been
> fine?
> > (TSEG1 = 0xC, TSEG2 = 0x1, SJW = 0x0).
> > Your BRP of 5 is correct for 16 cycles per bit at 125K
transmission
> speed on
> > a 12Meg Clock.
> >
> > In short what does trying:
> > TSEG1: (0xC << 16)
> > TSEG2: (0x1 << 20)
> > BRP: (0x5 << 0)
> > SJW: (0 << 14)
> > SPL_3X: (1 << 23)
> >
> > ie: C1BTR = 0x009C0005
> >
> > give you?
> >
> > Andy
> >
> > -----Original Message-----
> > From: l... [mailto:l...]On
> Behalf Of
> > Thiago Lima
> > Sent: 15 March 2007 03:28
> > To: l...
> > Subject: [lpc2000] CAN Bus - Baud rate problems with LPC2129
(I'm
> not
> > sure...)
> >
> >
> > Hello all LPC2000 friends,
> >
> > I'm developing an eletronic system using LPC2129 with a 12 MHz
> > crystal. I configured it to operate in 48 MHz and PCLK of 12 MHz
> ( 48
> > MHz / 4 ).
> >
> > At this moment I'm trying to make my LPC2129 communicate with
> another
> > electronic system, configured to operate in a CAN network
> > communicating in 125 kbps. This system that needs to communicate
> with
> > my system is also being developed and the source code were all
did
> > using loop back mode of this CAN controller (Not Philips).
> >
> > I'm writing this e-mail to ask to you if my CAN baud rate
> > configuration on LPC2129 is OK for communication in 125kbps.
> > The parameters are:
> >
> > TSEG1_7TQ ( 6 << 16 )
> > TSEG2_6TQ ( 5 << 20 )
> > BRP ( 5 << 0 )
> > SJW_1TQ ( 1 << 14 )
> > SPL_3X ( 1 << 23 )
> >
> > #define CanBitRate125k_12MHz (BRP | SJW_1TQ | TSEG1_7TQ |
> TSEG2_6TQ |
> > SPL_3X)
> >
> > I did the following division in order to find this parameters:
> >
> > Baudrate PCLK
> > = -------------------------------
> > (BRP+1) ((TSEG1+1)+(TSEG2+1)+3)
> >
> > 125000 12000000
> > = --------------------
> > (5+1) ((6+1)+(5+1)+3)
> >
> > Is this calculus correct for 12MHz and 125 Kbps (I think it is -
> but
> > I'm not so sure...).
> >
> > I developed the source code to send and receive data on CAN bus,
> being
> > helped, of course, by the excellent tutorials, app notes and
> routines
> > found on the internet. Using 2 can nodes with the same source
> code,
> > both with resistor of 120 ohms between RXD and TXD, and both
with
> > LPC2129 as the CAN controller, it worked!!! I could see data
being
> > delivered and received, using the UART as debug tool.
> >
> > If I connect the oscilloscope on this bus, could I see the
> waveforms
> > of CAN being transmited/received, on the bus?
> >
> > I know I configured one valid baud rate and I'm trafegating data
> on
> > the bus, to one LPC2129 to other...
> > But it does not communicate with the other node, not a LPC and
> not a
> > Philips component (with different equation for baud rate
> calculation).
> > This Can Controller chip could feel that one CAN node is on the
> bus,
> > because the error when trying to send a data on the bus
> (Transmission
> > Error - seems to be baud rate error, am I right?) is different
> when I
> > disconnect LPC from the microchip chip (Bus Off error when
> > disconnect).
> >
> > I would appreciate you giving me any help / hint, because I
really
> > don't know what to do. What are the best flags that I have to
> monitor
> > on the LPC2129 in order to get more information about this [ no
> > communication - baud ] error?
> >
> > Thiago
> > Electrical Engineer
> >
> >
> >
> >
> >
> >
> >
>
>
>
>
>
>
>
>
It now works perfectly:

FOR LPC2129 - 12MHz @ 125 kbps:

TSEG1: (0x7 << 16) <- the solution for this problem
TSEG2: (0x6 << 20) <- the solution for this problem
BRP: (0x5 << 0)
SJW: (0 << 14)
SPL_3X: (1 << 23)

TSEG2 + TSEG1 + 3 = 16

For MCP2515:

BRP = 2
#define PHSEG2_6TQ 0x05
#define PHSEG1_7TQ 0x30
#define PRSEG_2TQ 0x01
#define SJW_1TQ 0x40

On configuration mode ( <- the solution for this problem):

//Set CNF1 - Configuration 1
WriteSPI_MCP2515(CNF1, BRP | SJW_1TQ);

//Set CNF2 - Configuration 2
WriteSPI_MCP2515(CNF2,BTLMODE_CNF3 | PHSEG1_7TQ | PRSEG_2TQ |
SMPL_3X);

//Set CNF3 - Configuration 3
WriteSPI_MCP2515(CNF3, PHSEG2_6TQ | WAKFIL_DISABLED);

Thank you very much Andy!

You and Artic -> You did it!!!
--- In l..., "Andrew Berney" wrote:
>
> Hi Thiago,
>
> I had a chance to have a quick look at the chip you're using at the
other
> end and think I can probably now see where you're having a problem:
> I think you have an error in the MCP2515 defines - SJW is currently
set to
> 0x40 (2TQ) which sums your bit period to 17TQ in total not 16TQ.
> Your MCP2515 defines should therefore read:
> #define CAN_125kbps 2
> #define SJW_1TQ 0x0
> #define BTLMODE_CNF3 0x80
> #define PHSEG1_7TQ 0x30
> #define PRSEG_2TQ 0x01
> #define PHSEG2_6TQ 0x05
> #define SMPL_3X 0x40
> #define WAKFIL_DISABLED 0x00
>
> and the LPC equivalents as best I can see would then be:
> #define TSEG1 (0x8 << 16)
> #define TSEG2: (0x5 << 20)
> #define BRP: (0x5 << 0)
> #define SJW: (0x1 << 14)
> #define SPL_3X: (0x1 << 23)
>
> let me know if that gets it talking :)
>
> Andy
>
> -----Original Message-----
> From: l... [mailto:l...]On
Behalf Of
> tpfslima
> Sent: 15 March 2007 16:03
> To: l...
> Subject: [lpc2000] Re: CAN Bus - Baud rate problems with LPC2129
(I'm not
> sure...)
> Andy,
>
> Thanks for the informations.
> You can see the other part of the problem on this link, if you
want:
> http://forum.microchip.com/tm.aspx?m#7289 .
>
> I will try to make it work - make my can bus communicate on 125
kbs.
> I give you feedback of what problems I found.
> Thiago.
>
> --- In l..., "Andrew Berney" wrote:
> >
> > Hi Thiago,
> >
> > those values should give you the correct bit rate yes, with
TSEG1
> and 2
> > you're now simply changing when the sample period is conducted
over
> the 16
> > clk cycle. If it's still not working you might be better off
> posting the
> > info you've got for the device at the other end of the can bus.
> Hope you get
> > it working :)
> >
> > Andy
> >
> >
> >
> > -----Original Message-----
> > From: l... [mailto:l...]On
> Behalf Of
> > tpfslima
> > Sent: 15 March 2007 14:40
> > To: l...
> > Subject: [lpc2000] Re: CAN Bus - Baud rate problems with LPC2129
> (I'm not
> > sure...)
> >
> >
> > Thanks Andy for the help.
> >
> > If I try to use the following values:
> >
> > TSEG1: (0x7 << 16)
> > TSEG2: (0x6 << 20)
> > BRP: (0x5 << 0)
> > SJW: (0 << 14)
> > SPL_3X: (1 << 23)
> >
> > TSEG2 + TSEG1 + 3 = 16
> >
> > Is it ok for 12 MHz, 125 kbps?
> >
> > Baudrate PCLK
> > = -------------------------------
> > (BRP+1) ((TSEG1)+(TSEG2)+3)
> >
> > 125000 12000000
> > = --------------------
> > (5+1) ((7)+(6)+3)
> >
> > Thank you in advance...
> >
> > --- In l..., "Andrew Berney" wrote:
> > >
> > > Hi Thiago,
> > >
> > > How did you decide on TSEG1 and TSEG2 values as at a glance
they
> > don't
> > > appear to give 16 clock cycles per bit?
> > > If I remember correctly the delay from the sync point to the
> sample
> > point is
> > > TSEG1 + 1, and the delay from the sample point to the next
sync
> > point is the
> > > value in TSEG2 + TSEG1 + 3.
> > > Given that the default settings for can give 16 cycles per bit
> I'd
> > have
> > > expected TSEG2 + TSEG1 + 3 = 16. Yours appears to sum to 14,
so
> > are you
> > > sure that the device at the other end is set up the same way?
> > > I would have thought the default values for these would have
> been
> > fine?
> > > (TSEG1 = 0xC, TSEG2 = 0x1, SJW = 0x0).
> > > Your BRP of 5 is correct for 16 cycles per bit at 125K
> transmission
> > speed on
> > > a 12Meg Clock.
> > >
> > > In short what does trying:
> > > TSEG1: (0xC << 16)
> > > TSEG2: (0x1 << 20)
> > > BRP: (0x5 << 0)
> > > SJW: (0 << 14)
> > > SPL_3X: (1 << 23)
> > >
> > > ie: C1BTR = 0x009C0005
> > >
> > > give you?
> > >
> > > Andy
> > >
> > > -----Original Message-----
> > > From: l... [mailto:l...]
On
> > Behalf Of
> > > Thiago Lima
> > > Sent: 15 March 2007 03:28
> > > To: l...
> > > Subject: [lpc2000] CAN Bus - Baud rate problems with LPC2129
> (I'm
> > not
> > > sure...)
> > >
> > >
> > > Hello all LPC2000 friends,
> > >
> > > I'm developing an eletronic system using LPC2129 with a 12 MHz
> > > crystal. I configured it to operate in 48 MHz and PCLK of 12
MHz
> > ( 48
> > > MHz / 4 ).
> > >
> > > At this moment I'm trying to make my LPC2129 communicate with
> > another
> > > electronic system, configured to operate in a CAN network
> > > communicating in 125 kbps. This system that needs to
communicate
> > with
> > > my system is also being developed and the source code were all
> did
> > > using loop back mode of this CAN controller (Not Philips).
> > >
> > > I'm writing this e-mail to ask to you if my CAN baud rate
> > > configuration on LPC2129 is OK for communication in 125kbps.
> > > The parameters are:
> > >
> > > TSEG1_7TQ ( 6 << 16 )
> > > TSEG2_6TQ ( 5 << 20 )
> > > BRP ( 5 << 0 )
> > > SJW_1TQ ( 1 << 14 )
> > > SPL_3X ( 1 << 23 )
> > >
> > > #define CanBitRate125k_12MHz (BRP | SJW_1TQ | TSEG1_7TQ |
> > TSEG2_6TQ |
> > > SPL_3X)
> > >
> > > I did the following division in order to find this parameters:
> > >
> > > Baudrate PCLK
> > > = -------------------------------
> > > (BRP+1) ((TSEG1+1)+(TSEG2+1)+3)
> > >
> > > 125000 12000000
> > > = --------------------
> > > (5+1) ((6+1)+(5+1)+3)
> > >
> > > Is this calculus correct for 12MHz and 125 Kbps (I think it
is -
> > but
> > > I'm not so sure...).
> > >
> > > I developed the source code to send and receive data on CAN
bus,
> > being
> > > helped, of course, by the excellent tutorials, app notes and
> > routines
> > > found on the internet. Using 2 can nodes with the same source
> > code,
> > > both with resistor of 120 ohms between RXD and TXD, and both
> with
> > > LPC2129 as the CAN controller, it worked!!! I could see data
> being
> > > delivered and received, using the UART as debug tool.
> > >
> > > If I connect the oscilloscope on this bus, could I see the
> > waveforms
> > > of CAN being transmited/received, on the bus?
> > >
> > > I know I configured one valid baud rate and I'm trafegating
data
> > on
> > > the bus, to one LPC2129 to other...
> > > But it does not communicate with the other node, not a LPC and
> > not a
> > > Philips component (with different equation for baud rate
> > calculation).
> > > This Can Controller chip could feel that one CAN node is on
the
> > bus,
> > > because the error when trying to send a data on the bus
> > (Transmission
> > > Error - seems to be baud rate error, am I right?) is different
> > when I
> > > disconnect LPC from the microchip chip (Bus Off error when
> > > disconnect).
> > >
> > > I would appreciate you giving me any help / hint, because I
> really
> > > don't know what to do. What are the best flags that I have to
> > monitor
> > > on the LPC2129 in order to get more information about this [
no
> > > communication - baud ] error?
> > >
> > > Thiago
> > > Electrical Engineer
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
> >
> >
>
>