mitice
Joined: 12 Aug 2011 Posts: 4 Location: Taiwan
|
CAN problem with dspic30f6010A |
Posted: Thu Nov 24, 2011 5:09 am |
|
|
Hi everyone. I'm using dspic30f6010a with 10Mhz, and I set the Bit rate 500K. Now I encounter some problem that I can transmit data but not receive data. The following is my code. Could someone tell me how to modify.Thanks a lot. It never entered into can_kbhit().
Code: |
#include <30F6010A.h>
#fuses EC
#device *=16 ADC=12
#use delay(clock=10Mhz)
can_init();
can_set_mode(CAN_OP_CONFIG); //must be in config mode before params can be set
//設定can baud rate 500k
C1CFG1.brp=CAN_BRG_PRESCALAR;
C1CFG1.sjw=CAN_BRG_SYNCH_JUMP_WIDTH;
C1CFG2.prseg=CAN_BRG_PROPAGATION_TIME;
C1CFG2.seg1ph=CAN_BRG_PHASE_SEGMENT_1;
C1CFG2.sam=CAN_BRG_SAM;
C1CFG2.seg2phts=CAN_BRG_SEG_2_PHASE_TS;
C1CFG2.seg2ph=CAN_BRG_PHASE_SEGMENT_2;
C1CFG2.wakfil=CAN_BRG_WAKE_FILTER;
//設定can 中斷
enable_interrupts(INT_CAN1);
can_enable_interrupts(RX0 | RX1 );
enable_interrupts(INTR_GLOBAL);
can_set_mode(CAN_OP_NORMAL);
can_putd(0x280,CAN_data,8,3,FALSE,FALSE);
printf("Running...........\n");
while(1)
{
if ( can_kbhit() ) //if data is waiting in buffer...
{
if(can_getd(rx_id, &buffer[0], rx_len, rxstat)) { //...then get data from buffer
printf("\r\nGOT: BUFF=%U ID=%LU LEN=%U OVF=%U ", rxstat.buffer, rx_id, rx_len, rxstat.err_ovfl);
printf("FILT=%U RTR=%U EXT=%U INV=%U", rxstat.filthit, rxstat.rtr, rxstat.ext, rxstat.inv);
printf("\r\n DATA = ");
for (i=0;i<rx_len;i++) {
printf("%X ",buffer[i]);
}
printf("\r\n");
if (rx_id == 300) {
printf("GET DATA\r\n\r\n");
}
}
}
}
|
|
|