Hardware manual
RX600 Series CAN Application Programming Interface
R01AN0339EU0203 Rev. 2.03 Page 24 of 29
Mar 23, 2013
/* Tell user if CAN bus status changed.
All Status bits are read only. */
if (error_bus_status[ch_nr] != error_bus_status_prev[ch_nr])
{
switch (error_bus_status[ch_nr])
{
/* Error Active. */
case R_CAN_STATUS_ERROR_ACTIVE:
/* Only report if there was a previous error. */
if (error_bus_status_prev[ch_nr] > R_CAN_STATUS_ERROR_ACTIVE)
{
if (ch_nr == 0)
DisplayString(LCD_LINE1, "bus0: OK");
else
DisplayString(LCD_LINE2, "bus1: OK");
/* Show user */
Delay(0x400000);
}
/* Restart if returned from Bus Off. */
if (error_bus_status_prev[ch_nr] == R_CAN_STATUS_BUSOFF)
{
/* Restart CAN */
if (R_CAN_Create(0) != R_CAN_OK)
app_err_nr |= APP_ERR_CAN_PERIPH;
/* Restart CAN demos even if only one channel failed. */
InitCanApp();
}
break;
/* Error Passive. */
case R_CAN_STATUS_ERROR_PASSIVE:
/* Continue into Bus off case to display. */
/* Bus Off. */
case R_CAN_STATUS_BUSOFF:
default:
/* The application should take note of the following state and
Stop communication. */
app_state[ch_nr] = R_CAN_STATUS_BUSOFF;
if (ch_nr == 0)
DisplayString(LCD_LINE1,"bus0: ");
else
DisplayString(LCD_LINE2,"bus1: ");
/* Show user */
LcdShow2DigHex((uint8_t)error_bus_status[ch_nr], ch_nr*16 + 6);
Delay(0x400000);
nr_times_reached_busoff[ch_nr]++;
break;
}
error_bus_status_prev[ch_nr] = error_bus_status[ch_nr];
}/* end HandleCanBusState() */
Using CAN Error Interrupts.