The documentation described twai driver but I could not find this, only "/drivers?can.h" So I used the Can driver and followed example code in documentation on ESP-IDF site.
The can appears to configure and load without error but when attempting to transmit I get error 259 (0x0103) and connect understand what this error is. My code is below (I am using idf.py inside vscode). TX pin is GPIO 26 and RX pin is GPIO27.
Thanks in advance for any help. This is first attempt at using CANBUS
Code: Select all
void ConfigCanBus(void)
{
can_general_config_t g_config = CAN_GENERAL_CONFIG_DEFAULT(GPIO_NUM_26,GPIO_NUM_27,CAN_MODE_NORMAL);
can_timing_config_t t_config = CAN_TIMING_CONFIG_500KBITS();
can_filter_config_t f_config = CAN_FILTER_CONFIG_ACCEPT_ALL();
if(can_driver_install(&g_config, &t_config, &f_config) == ESP_OK)
{
printf("Can Bus driver installed ok\n");
}
else
{
printf("Failed to install CanBus Drive \n");
}
if(can_start() == ESP_OK)
{
printf("CanBus driver started ok\n");
}
else
{
printf("CanBus driver failed to start\n");
}
}
void SendCanBusMessage(void)
{
can_message_t message;
message.flags = CAN_MSG_FLAG_NONE;
message.identifier = 0xAA; //std fram = 2 byte ID, extended = 4 byte ID
message.data_length_code = 4;
for(int i = 0; i < 4; i++)
{
message.data[i] = i;
}
esp_err_t result = can_transmit(&message,pdMS_TO_TICKS(1000));
if(result == ESP_OK)
{
printf("CanBus message sent\n");
}
else
{
printf("CanBus failed to send, error code %d \n",result);
}
}