Interfacing SR73 Radar with AT90CAN128

General discussion on mikroC PRO for AVR.
Post Reply
Author
Message
itpartha
Posts: 2
Joined: 12 Jul 2022 11:47

Interfacing SR73 Radar with AT90CAN128

#1 Post by itpartha » 12 Jul 2022 12:13

Dear All,

We are trying to interface SR73 radar sensor having CANBUS baud rate 500 kbps to AT90CAN128 microcontroller.
The AT90CAN128 is running with 11.0592 MHz external crystal.

We are using the following code to initialize the CAN.

can_flag_init = _CAN_CONFIG_SAMPLE_THRICE & _CAN_CONFIG_XTD_MSG;
CANInitialize(1, 6, 3, 3, 1, can_flag_init);
CANSetOperationMode(_CAN_MODE_ENABLE, 0xFF);

but unable to set baud rate to 500kbps as we don't know the parameters of the following CAN library function.
CANSetBaudRate(char SJW, char BRP, char PHSEG1, char PHSEG2, char PROPSEG, char CAN_CONFIG_FLAGS);
as we don't know the values of SJW, BRP, PHSEG1, PHSEG2, PROPSEG and CAN_CONFIG_FLAGS for the AT90CAN128.

Please suggest how we can communicate with the radar sensor.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Interfacing SR73 Radar with AT90CAN128

#2 Post by filip » 12 Jul 2022 14:17

Hi,

You may use CAN calculator application to configure CAN bus :
https://www.mikroe.com/can-calculator

Regards,
Filip.

itpartha
Posts: 2
Joined: 12 Jul 2022 11:47

Re: Interfacing SR73 Radar with AT90CAN128

#3 Post by itpartha » 23 Aug 2022 12:10

Hello

We are still unable to receive correct frame ID and data from the radar having CAN baud rate 250K using the AT90CAN128 microcontroller with 8MHz crystal and 250K UART baud rate (for which the error rate is supposed to be 0%).
While the CANtoUSB adapter supplied by the radar manufacturer is correctly receiving CAN frame ids 0x0000060b and 0x0000060a along with valid data.
We have used the CANculator tool to get the values SJW, BRP, PSREG1, PSREG2, PROPSEG and tried all the settings for 8MHz crystal. But none of these are useful to get correct frame IDs and data from the Radar.
The following is our source code for MicroC AVR IDE. Please let us know what I am doing wrong.

const unsigned int SJW = 4;
const unsigned int BRP = 2;
const unsigned int PHSEG1 = 4;
const unsigned int PHSEG2 = 6;
const unsigned int PROPSEG = 5;
const unsigned int CAN_CONFIG_FLAGS = _CAN_CONFIG_SAMPLE_ONCE & _CAN_CONFIG_STD_MSG;


char can_flag_rx, can_flag_tx, len_rx, len_tx;
char data_rx[8], data_tx[64], data_val[9];

long int id_rx;

void main() {
char i;

len_tx = 255;

Init();
Delay_ms(50);

while(1)
{
Delay_ms(1);

while(CANRead(&id_rx, data_rx, &len_rx, &can_flag_rx) > 0) // Read 8 bytes from CAN
{
asm{WDR;}

LongIntToHex(id_rx, data_val);
Tx_Char_PC(data_val[0]);
Tx_Char_PC(data_val[1]);
Tx_Char_PC(data_val[2]);
Tx_Char_PC(data_val[3]);
Tx_Char_PC(data_val[4]);
Tx_Char_PC(data_val[5]);
Tx_Char_PC(data_val[6]);
Tx_Char_PC(data_val[7]);
Tx_Char_PC(data_val[8]);
Tx_Char_PC('\r');

for(i = 0; i < len_rx; i++)
{
Tx_Char_PC(data_rx);
}
Tx_Char_PC('\r');
}

asm{WDR;}
}
}


void Tx_Char_PC(char c)
{
while(!(UCSR1A & (1 << UDRE1)))
{
Delay_us(5);
}
UDR1 = c;
}

void Init()
{
LED_1_ACTIVE;
LED_2_ACTIVE;

LED_1 = 1;
LED_2 = 1;

CANInitialize(SJW, BRP, PHSEG1, PHSEG2, PROPSEG, CAN_CONFIG_FLAGS);

SREG.F7 = 0; // Global Interrupt disable

UBRR1H = 0;
UBRR1L = 1; // UBRRL=1 for 250000 Baud rate 8MHz crystal

UCSR1B.F7 = 1;
UCSR1A.F7 = 1;
UCSR1B.F4 = 1;
UCSR1B.F3 = 1;

SREG.F7 = 1; // Global Interrupt enable

TCCR1B = 5; // 4 for 43200Hz, 5 for 10800Hz
TCNT1H = 0;
TCNT1L = 0;

WDTCR = 0x18;
WDTCR = 0x0F;
asm{WDR;}
}

Post Reply

Return to “mikroC PRO for AVR General”