/******************************************************** Name : main.c **********************************************************/ // Include Files #include "board.h" #include "can.h" #include "spi.h" #include "gpio.h" #include "pm.h" #include "dip204.h" #include "intc.h" #include "delay.h" #include "string.h" unsigned short spidata; unsigned short *spidatareadpointer; unsigned short spidataread; unsigned long i; unsigned short temp; #define CAN_1000kbps 1 #define CAN_500kbps 5 #define CAN_250kbps 7 #define CAN_125kbps 10 #define R 82 UINT16 xmit =0; UINT32 Ident; UINT8 msg[8], mSize; int main(void) { spidatareadpointer=&spidataread; pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); // Configures the MCP2515 SPI communication. config_SPI_SPARE(); // Configures the display SPI communication. config_dpi204(); // Enables receive interrupts. Disable_global_interrupt(); INTC_init_interrupts(); Enable_global_interrupt(); // Delay to let the Oscillator get started delay_init( FOSC0 ); // Initializes the display dip204_init(100,1); dip204_clear_display(); InitializeCAN(0,CAN_125kbps); while(1){ //Clear memory contents ClearMessages(msg); //Read any message available if(CANRxReady(0)){ if( CANGetMsg(0, &Ident, msg, &mSize )) // Gets message and returns //TRUE if message received. {// Evk1100PrintDisplay prints 4 message values, the Identifier and the data size on the display Evk1100PrintDisp(&Ident, msg, &mSize ); delay_ms(1000); dip204_clear_display(); } } // Send messages if possible if(CANTxReady(0)) { msg[0]=0; msg[1]=100; msg[2]=100; msg[3]=0; msg[4]=100; msg[5]=0x06; msg[6]=0x07; msg[7]=50; // Channel, Identifier (max 0x1fffffff (29 bits)), Message, Number of bytes, R //or 0 (Remote frame or no remote frame). CANSendMsg( 0, 0x01, msg, 8, 0 ); delay_ms(1000); dip204_clear_display(); } } return 0; }