Hello Friends,
I am very new to CAN bus protocol, now i am using AT90CAN128 controller to receive the can message.
I have written the source code from some example codes such a way that it will receive the CAN data and put it in to USART1.
I need to check using hyperterminal or procomm.
Can any one look into my source code?
I think the problem is in source code because i`m using ATMEl Development kit for AVR microcontrollers with CAN "DVK90CAN1". Datasheet of it is attached with this post.
I am using IAR Embedded Workbench compiler.
my source code is:
/************************************************** * Description: * Copyright 1996 -2005 IAR Systems. All rights reserved. * $Revision: 1.1 $ **************************************************/ #include#include char datas[8]; int mob_number; ////// USART INITIALIZATION ////// void USART1_Init() { UCSR1A=0X00; UCSR1B=0XD8; UCSR1C=0X06; UBRR1H=0X00; UBRR1L=0X67; } ////// CAN INITIALIZATION ////// void can_init(void) { CANGCON=0X80; // Abort request while((CANGSTA & 0X04) == 0X04); // To check if ENFG bit has been cleared. CANGIE=0XB0; // Alternate way is enable RX,TX and all can interrupt CANEN1=0X00; // Enable MOB0 CANEN2=0X01; CANIE2=0XFF; // Enable Mob0 to Mob7 CANIE1=0XFF; // Enable Mob8 to Mob15 CANBT1=0X06; // Set baud rate to 250kb CANBT2=0X08; CANBT3=0X48; for(mob_number = 0; mob_number < 15; mob_number++) { CANPAGE = 1<< 4; // Select Mob0 CANCDMOB = 0X00; // Disable all transmission and reception CANSTMOB=0X00; } CANIDM1 = 0X00; // Clear mask, let all IDs pass CANIDM2 = 0X00; CANIDM3 = 0X00; CANIDM4 = 0X00; CANGCON = 0X02; // Enable CAN while((CANGSTA & 0X04) != 0X04); // Wait until CAN bus being enabled } ////// USART TRANSMIT ////// void USART1_Transmit(unsigned char data1) { /* wait for empty transmit buffer */ while(!(UCSR1A & (1<<UDRE1))) ; /* Put the data into buffer, sends the data */ UDR1=data1; } void USART1_Transmit_string(char *str) { while(*str!='\0') USART1_Transmit(*str++); } ////// CAN RECEIVE ////// void can_rx(void) { CANPAGE = 1<<4; // select mob0 CANCDMOB = 0X80; // enable reception } void can_rx_inter(void) { int i; if((CANSTMOB & 0X20) == 0X20) // Check if RXOK flag has been set { CANSTMOB &= 0XDF; // Clear RXOK flag for(i=0;i<8;i++) { datas[i] = CANMSG; // Move data received } USART1_Transmit_string("datas[]"); } } void main(void) { can_init(); USART1_Init(); while(1) { can_rx(); can_rx_inter(); } }
$ Fixed CODE tags - JS $
The incoming can message baud rate is 250kbaud.
I want to receive the CAN data and i need to send it through USART using AT90CAN128.
Please any one help me out.
I would be very thankful if you do mu needy.