bad variables

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

bad variables

跳至解决方案
3,660 次查看
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.
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,720 次查看
Seitec
Contributor III
I find it, bad declaration. Thank you very much all for you time.

在原帖中查看解决方案

0 项奖励
回复
6 回复数
1,720 次查看
Lundin
Senior Contributor IV
Impossible to tell without the whole code.
0 项奖励
回复
1,720 次查看
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 项奖励
回复
1,720 次查看
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 项奖励
回复
1,720 次查看
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 项奖励
回复
1,721 次查看
Seitec
Contributor III
I find it, bad declaration. Thank you very much all for you time.
0 项奖励
回复
1,720 次查看
kef
Specialist I
Let me guess, is CAN0SendFrame() prototype declared before you call it? No warnings about missing prototype?
0 项奖励
回复