bad variables

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

bad variables

Jump to solution
2,554 Views
Seitec
Contributor III
Hello,

I have problem with my function.
unsigned char CAN0SendFrame (unsigned long id, unsigned char priority,unsigned char length, unsigned char *txdata);

I would like have unsigned long 0xE0000000 but if I forward this variable function instead E0000000 there is E000. Do anybody know please where is mistake?

Thank you very much.

I am using HC9S12DP256 and codewarrior.
Labels (1)
Tags (1)
0 Kudos
1 Solution
614 Views
Seitec
Contributor III
I find it, bad declaration. Thank you very much all for you time.

View solution in original post

0 Kudos
6 Replies
614 Views
Lundin
Senior Contributor IV
Impossible to tell without the whole code.
0 Kudos
614 Views
Seitec
Contributor III
#define ST_ID_100 0xE0000000


unsigned char CAN0SendFrame (unsigned long id, unsigned

char priority,unsigned char length, unsigned char *txdata){
unsigned char vojta[] = "ERR_BUFFER_FULL";
char txbuffer;
int index;
if (!CAN0TFLG) /* Is Transmit Buffer full?? */

return *(vojta);
CAN0TBSEL = CAN0TFLG; /* Select lowest empty buffer */
txbuffer = CAN0TBSEL; /* Backup selected buffer */
/* Load Id to IDR Register */
*((unsigned long *) ((unsigned long)(&CAN0TXIDR0))) = id;
for (index=0;index.
.
.



call function

CAN0SendFrame (ST_ID_100, 0x00, delka, txdata1);
0 Kudos
614 Views
Lundin
Senior Contributor IV
The cause of the bug is that you aren't setting the IDE bit in the extended CAN frame.

For 29-bit id you must always set IDE. In MSCAN, 29-bit and 11-bit share the same registers. If the IDE bit isn't set, the CAN controller will interpret the id as 11-bit and thus only use the 11 most significant bits. This means that 0xE000 will be used and you will get a 11-bit CAN id of 0x700.

Read "3.2.2 Programmer's model of message storage" in the MSCAN manual for detailed info.

---

Also, this line seems suspicious:

if (!CAN0TFLG) /* Is Transmit Buffer full?? */
return *(vojta);

This will return the letter 'E'. How did you intend this to work? You can't return a pointer to a local string either, that will only give rubbish to the caller.
0 Kudos
614 Views
Seitec
Contributor III
Yes I know but variable where is mistake, it is variable which I would like copy to IDRx where is IDE.
0 Kudos
615 Views
Seitec
Contributor III
I find it, bad declaration. Thank you very much all for you time.
0 Kudos
614 Views
kef
Specialist I
Let me guess, is CAN0SendFrame() prototype declared before you call it? No warnings about missing prototype?
0 Kudos