|
|
View previous topic :: View next topic |
Author |
Message |
menthongps
Joined: 08 Nov 2018 Posts: 6
|
|
Posted: Thu Nov 08, 2018 10:23 am |
|
|
hi all,
Can help me i have 2 problem with this code?
1: can_putd() always loop at 0x111 and can't call 0x222.
2: delay between two messages i monitor only 0.2ms not is 10ms at my code.
I tried a lot of change but can_putd() alway loop and can't exit to call other function.
Thanks very much for help!
my code:
Code: |
#include <18F4680.h>
#use delay(crystal=20MHz)
#include <can-18F4580.c>
#define can_tbe_0() (!TXB0CON.txreq)
void main()
{
int data[8]={7,6,5,4,3,2,1,0};
can_init();
while(TRUE)
{
if (can_tbe()) can_putd(0x111, data, 8, 3, 0, 0);
delay_ms(10);
if (can_tbe()) can_putd(0x222, data, 8, 3, 0, 0);
}
} |
|
|
|
menthongps
Joined: 08 Nov 2018 Posts: 6
|
|
Posted: Thu Nov 08, 2018 10:31 am |
|
|
I think may be have problem with this
but i not understand why this always loop!
Code: |
int1 can_putd(unsigned int32 id, unsigned int *data, unsigned int len, unsigned int priority, int1 ext, int1 rtr) {
unsigned int i;
unsigned int *txd0;
unsigned int port;
txd0=&TXRXBaD0;
// find empty transmitter
// map access bank addresses to empty transmitter
if (!TXB0CON.txreq)
{
if(curfunmode==CAN_FUN_OP_LEGACY)
CANCON.win=CAN_WIN_TX0;
else
ECANCON.ewin=TX0;
port=0;
}
else if (!TXB1CON.txreq)
{
if(curfunmode==CAN_FUN_OP_LEGACY)
CANCON.win=CAN_WIN_TX1;
else
ECANCON.ewin=TX1;
port=1;
}
else if (!TXB2CON.txreq)
{
if(curfunmode==CAN_FUN_OP_LEGACY)
CANCON.win=CAN_WIN_TX2;
else
ECANCON.ewin=TX2;
port=2;
}
else if (!B0CONT.txreq && BSEL0.b0txen)
{
ECANCON.ewin=TXRX0;
port=3;
}
else if (!B1CONT.txreq && BSEL0.b1txen)
{
ECANCON.ewin=TXRX1;
port=4;
}
else if (!B2CONT.txreq && BSEL0.b2txen)
{
ECANCON.ewin=TXRX2;
port=5;
}
else if (!B3CONT.txreq && BSEL0.b3txen)
{
ECANCON.ewin=TXRX3;
port=6;
}
else if (!B4CONT.txreq && BSEL0.b4txen)
{
ECANCON.ewin=TXRX4;
port=7;
}
else if (!B5CONT.txreq && BSEL0.b5txen)
{
ECANCON.ewin=TXRX5;
port=8;
}
else
{
#if CAN_DO_DEBUG
can_debug("\r\nCAN_PUTD() FAIL: NO OPEN TX BUFFERS\r\n");
#endif
return(0);
}
//set priority.
TXBaCON.txpri=priority;
//set tx mask
can_set_id(TXRXBaID, id, ext);
//set tx data count
TXBaDLC=len;
TXBaDLC.rtr=rtr;
for (i=0; i<len; i++) {
*txd0=*data;
txd0++;
data++;
}
//enable transmission
TXBaCON.txreq=1;
if(curfunmode==CAN_FUN_OP_LEGACY)
CANCON.win=CAN_WIN_RX0;
else
ECANCON.ewin=RX0;
#if CAN_DO_DEBUG
can_debug("\r\nCAN_PUTD(): BUFF=%U ID=%LX LEN=%U PRI=%U EXT=%U RTR=%U\r\n", port, id, len, priority, ext, rtr);
if ((len)&&(!rtr)) {
data-=len;
can_debug(" DATA = ");
for (i=0;i<len;i++) {
can_debug("%X ",*data);
data++;
}
can_debug("\r\n");
}
#endif
return(1); |
|
|
|
menthongps
Joined: 08 Nov 2018 Posts: 6
|
|
Posted: Fri Nov 09, 2018 6:19 am |
|
|
nobody can help!!!! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Nov 09, 2018 9:09 am |
|
|
OK, cut a New program to flash an LED at 1Hz. Get it to work.
I suspect your 'clock' is not running at the proper speed as the delay_ms() is'nt working ?
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Fri Nov 09, 2018 9:16 am |
|
|
txrtr needs to be 1.
You are not issuing a request for transmission. |
|
|
menthongps
Joined: 08 Nov 2018 Posts: 6
|
|
Posted: Fri Nov 09, 2018 9:48 am |
|
|
thank, i make toggle led it is ok.
the problem i think on transmit buffer, it fill in full with A message, always call A and never call B message.
this is capture CAN logic.
i can't sent data 0x222 it alway loop in 0x111.
0.000677500000000,0,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.001741062500000,1,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.002804625000000,2,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.003868187500000,3,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.004931750000000,4,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.005995312500000,5,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.007058875000000,6,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.008122437500000,7,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.009186000000000,8,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.010249562500000,9,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.011313125000000,10,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.012376687500000,11,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.013440250000000,12,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.014503812500000,13,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.015567375000000,14,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.016630937500000,15,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.017694500000000,16,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.018758062500000,17,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.019821625000000,18,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.020885187500000,19,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.021948750000000,20,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.023012312500000,21,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.024075875000000,22,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.025139437500000,23,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.026203000000000,24,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.027266562500000,25,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.028330125000000,26,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.029393687500000,27,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.030457312500000,28,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.031520875000000,29,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK
0.032584437500000,30,DATA,0x111,0x8,0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00,0x2E24,NAK |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Fri Nov 09, 2018 11:36 am |
|
|
Yes. As I have already pointed out, you are not telling it to start a transmission, so it transmits when the buffer gets full only.
You need to set txrtr, in your can_putd commands. |
|
|
menthongps
Joined: 08 Nov 2018 Posts: 6
|
|
Posted: Sat Nov 10, 2018 6:25 pm |
|
|
Anyone know please help me!
How to put messenger to buffer and how to send it out TXT.
Like i want send the message A, B, C at one time, how to do?
I see time between A and B is about 70us, B and C also.
So i know message have priority, but important i don't know is command to put message to buffer and send it.
How to know message has sent and call next message ?
I see my code buffer is over fill by only one 111 message so how to put both A,B,C to one buffer or put A to Buffer B0, B to buffer B1, C to buffer B2 and call them with correct sequence ?
Big Thank!!!!
Example:
0.011816437500000,5,DATA,0x12F,0x8,0xFA 0x05 0xE0 0x03 0x00 0x78 0x00 0x00,0x4346,ACK
0.012312812500000,6,DATA,0x22F,0x8,0x02 0x07 0x00 0x00 0x00 0x00 0x05 0xE0,0x6707,ACK
0.012801125000000,7,DATA,0x121,0x8,0x00 0xFA 0x00 0x00 0x05 0xE0 0x31 0x00,0x1A3D,ACK
0.013285625000000,8,DATA,0x221,0x8,0x65 0x01 0x00 0x00 0x00 0x00 0x00 0x00,0x7E9D,ACK
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
menthongps
Joined: 08 Nov 2018 Posts: 6
|
|
Posted: Wed Jan 16, 2019 7:15 am |
|
|
hello all!
I'm not programer so verry difficult to write code.
if have any solution please tell me.
I can pay for code.
my problem is how to sent messenge like:
1,2,3,4 delay_ms(100) 1,2,3,4 delay_ms(100).......
thanks all! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|