I am working on a project based on the ESP32 processor and Arduino framework, which communicates with another board via CANBUS protocol.
The bitrate is 125k so it is presumably "fast".
I am using the Sandeep Mistry library or also known as adafruit_CAN which is compatible with a Texas Instruments SN65HVD230 CAN transceiver.
I use freeRTOS for a method that will receive frames per socket, and write them to the board.
The library itself provides a callback attached to the ISR to receive the responses.
This is where my problem begins. If I send it a frame per second, everything is wonderful, but when I start to send them every 200 ms, I can see (with a CAN analyzer connected to the bus from the PC) that the frames are arriving, they are received on the card and it is answering, but my transceiver does not trigger the callback.
I have tried forgetting about the callback and using another RTOS method for reading with the same result.
Any ideas?
This method is iterating through a task, and if the vector contains a CAN_message_t object it writes it to the CAN, this works correctly.
void vTaskCANBUSWriteLoop(void *p)
{
Serial.print("Writer Task");
for (;;)
{
if (!my_global_vector.empty() )
{
response_broker_t myObject = my_global_vector.front();
my_global_vector.pop();
writePlot(myObject);
}
vTaskDelay(200 / portTICK_PERIOD_MS);
}
}
This other method is according to the documentation. It works well if the program does not exceed one send per second. If it exceeds that the program continues writing but the callback is not fired. There is a check if it matches an ID. In the parser I see that this ID is the one that is going in.
void canCallback(int packetSize)
{
static uint32_t lastTime = 0;
if (can_reader.packetId() == BOARD_ANSWER1 || can_reader.packetId() == BOARD_ANSWER2)
{
if (packetSize)
{
uint8_t buf[8];
while (can_reader.available())
{
CAN.readBytes(buf, sizeof(buf));
}
uint8_tArrayToHexString2(buf, sizeof(buf), rapidResponse);
}
}
}
This is a method I use to convert to hexString. It's not relevant but it may bring more clarity:
void uint8_tArrayToHexString2(uint8_t *data, size_t len, char *output)
{
static const char hexChars[] = "0123456789ABCDEF";
for (size_t i = 0; i < len; ++i)
{
output[i * 3] = hexChars[(data[i] >> 4) & 0xF];
output[i * 3 + 1] = hexChars[data[i] & 0xF];
output[i * 3 + 2] = ' ';
}
output[len * 3 - 1] = '\0';
}