I am trying to use a CAN SPI click 3.3V board that I have attached to the Ready for XMEGA Boards.
Using the examples and two boards I can successfully compile the programs but don't get a SCLK
to the MCP2515 on either board.
Does the CANSPI LIBRARY work with an xMega?
The USB UART works as does my other code (I have removed for simplicity).
Here is the modified example i used for one board,
Code: Select all
program USB_CAN_Test_01;
var uart_rd : byte;
Rxchar1 : char;
TxChar1 : char;
Command1 : String[30];
Command2 : String[30];
Cmnd : integer;
var Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags : byte; // can flags
Rx_Data_Len : byte; // received data length in bytes
RxTx_Data : array[8] of byte; // can rx/tx data buffer
Msg_Rcvd : byte; // reception flag
Tx_ID, Rx_ID : longint; // can rx and tx ID
// CANSPI module connections
var CanSpi_CS : sbit at PORTD_OUT.0;
CanSpi_CS_Direction : sbit at PORTD_DIR.0;
CanSpi_Rst : sbit at PORTD_OUT.2;
CanSpi_Rst_Direction : sbit at PORTD_DIR.2;
// End CANSPI module connections
begin
// Internal oscillator selection
OSC_CTRL := 0x02;
while RC32MRDY_bit = 0 do nop;
CPU_CCP := 0xD8;
CLK_CTRL := 1;
PORTQ_DIRSET := 255; // Set PORTQ as output
Sound_Init(PORTQ_OUT, 2); // Initialize the pin PQ2 for playing sound
Sound_Play(1000, 500); // Initilize / Start Beep
UARTC0_Init(921600);
Delay_ms(100);
UARTC0_Write_Text('Embedded Systems');
UARTC0_Write(13);UARTC0_Write(10);
Can_Init_Flags := 0; //
Can_Send_Flags := 0; // clear flags
Can_Rcv_Flags := 0; //
Can_Send_Flags := _CANSPI_TX_PRIORITY_0 and // form value to be used
_CANSPI_TX_XTD_FRAME and // with CANSPIWrite
_CANSPI_TX_NO_RTR_FRAME;
Can_Init_Flags := _CANSPI_CONFIG_SAMPLE_THRICE and // form value to be used
_CANSPI_CONFIG_PHSEG2_PRG_ON and // with CANSPIInit
_CANSPI_CONFIG_XTD_MSG and
_CANSPI_CONFIG_DBL_BUFFER_ON and
_CANSPI_CONFIG_VALID_XTD_MSG;
SPID_Init(); // initialize SPI1 module
CANSPIInitialize(1,3,3,3,1,Can_Init_Flags); // Initialize external CANSPI module
CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF); // set CONFIGURATION mode
CANSPISetMask(_CANSPI_MASK_B1,-1,_CANSPI_CONFIG_XTD_MSG); // set all mask1 bits to ones
CANSPISetMask(_CANSPI_MASK_B2,-1,_CANSPI_CONFIG_XTD_MSG); // set all mask2 bits to ones
CANSPISetFilter(_CANSPI_FILTER_B2_F4,3,_CANSPI_CONFIG_XTD_MSG); // set id of filter B1_F1 to 3
CANSPISetOperationMode(_CANSPI_MODE_NORMAL,0xFF); // set NORMAL mode
Tx_ID := 12111;
while (TRUE) do // Endless loop
Begin
RxTx_Data[0] := 2;
CANSPIWrite(Tx_ID, RxTx_Data, 1, Can_Send_Flags);
Msg_Rcvd := CANSPIRead(Rx_ID , RxTx_Data , Rx_Data_Len, Can_Rcv_Flags);
if ((Rx_ID = 3) and Msg_Rcvd) then
begin
Inc(RxTx_Data[0]);
Delay_ms(10);
CANSPIWrite(Tx_ID, RxTx_Data, 1, Can_Send_Flags);
end;
end;
end.