Beck-Sisyphus wrote:
When I configure the driver with different pinout, in my case is GPIO5->CAN TX and GPIO16->CAN RX, the menuconfig shows they are invalid pins.
it is cause the pins are selected as "Valid pins" in the menuconfig file for CAN-
feel free to set your own "Valid" config on this
change here the "valid pins" and
here
4 and 5 are the successfully tested pins,
you can use other too
Beck-Sisyphus wrote:
Running the code on both device successfully, but no communication yet.
Is there a way to change the GPIO pinout for CAN bus?
Platform: ESP-IDF
Board: ESP-WROOM-32
CAN Transceiver: SN65HVD232 (3.3V)
Termination: 120 Ohm
yes. see the preview text.
Beck-Sisyphus wrote:
Another question is about CAN bus protocol itself.
Currently I planned to have one masters on the bus and two slaves,
with masters and slaves both sending and receiving. How to define the address of the three device?
you can set example "itself" node
and send the message by using this itself node address.
example a "slave" - i will named it as CAN-Unit
send the ADC Value of one ADC Pin
and use the itself node address for the frame for this.
( the frame content not a delivery ( "Receiver" ) address, the frame content the "Transceiver" )
this is the base of CAN.
example with an counter :
Code: Select all
void task_CAN_TX(void* pvParameters) {
CAN_frame_t __TX_frame;
uint32_t counter = 0;
__TX_frame.MsgID = CONFIG_ESP_CAN_NODE_ITSELF; // address from menuconfig set
__TX_frame.DLC = 8;
__TX_frame.data.u8[0] = 'E';
__TX_frame.data.u8[1] = 'S';
__TX_frame.data.u8[2] = 'P';
__TX_frame.data.u8[3] = '-';
__TX_frame.data.u8[4] = 'C';
__TX_frame.data.u8[5] = 'A';
__TX_frame.data.u8[6] = 'N';
__TX_frame.data.u8[7] = counter;
while(1) {
__TX_frame.data.u8[7] = counter;
CAN_write_frame(&__TX_frame);
/* printf("Frame from : 0x%08x, DLC %d \n", __TX_frame.MsgID, __TX_frame.DLC);
printf("D0: 0x%02x, ", __TX_frame.data.u8[0]);
printf("D1: 0x%02x, ", __TX_frame.data.u8[1]);
printf("D2: 0x%02x, ", __TX_frame.data.u8[2]);
printf("D3: 0x%02x, ", __TX_frame.data.u8[3]);
printf("D4: 0x%02x, ", __TX_frame.data.u8[4]);
printf("D5: 0x%02x, ", __TX_frame.data.u8[5]);
printf("D6: 0x%02x, ", __TX_frame.data.u8[6]);
printf("D7: 0x%02x\n", __TX_frame.data.u8[7]);
printf("==============================================================================\n");
printf("..Frame written\n");
*/
vTaskDelay( 1000 / portTICK_PERIOD_MS); // to see ( printf on receiver side ) what happend..
counter++;
if (counter >= 256) counter = 0;
}
}
each "Master" - i name it CAN-Controll
then decides to use the Information for a "address"
example:
this prints each Info..
if you want to use a Info of a certain address, check out the line
..
Code: Select all
if ( __RX_frame.MsgID == YOUR_CHOICE) {..
example:
Code: Select all
void task_CAN( void *pvParameters ){
(void)pvParameters;
//frame buffer
CAN_frame_t __RX_frame;
//create CAN RX Queue
CAN_cfg.rx_queue = xQueueCreate(10,sizeof(CAN_frame_t));
//start CAN Module
CAN_init();
while (1){
//receive next CAN frame from queue
if(xQueueReceive(CAN_cfg.rx_queue,&__RX_frame, 3*portTICK_PERIOD_MS)==pdTRUE){
//do stuff!
/* brief: rudi
* new we switch to NODE Identifier here
* only if we are interest to this comming node
* we print / use the node date where commes in from
*
*/
/* @Beck: here is your magic if you want only from a certain node */
// if ( __RX_frame.MsgID == YOUR_CHOICE) {
// printf("New Frame form 0x%08x, DLC %d, dataL: 0x%08x, dataH: 0x%08x \r\n",__RX_frame.MsgID, __RX_frame.DLC, __RX_frame.data.u32[0],__RX_frame.data.u32[1]);
printf("Frame from : 0x%08x, DLC %d \n", __RX_frame.MsgID, __RX_frame.DLC);
printf("D0: 0x%02x, ", __RX_frame.data.u8[0]);
printf("D1: 0x%02x, ", __RX_frame.data.u8[1]);
printf("D2: 0x%02x, ", __RX_frame.data.u8[2]);
printf("D3: 0x%02x, ", __RX_frame.data.u8[3]);
printf("D4: 0x%02x, ", __RX_frame.data.u8[4]);
printf("D5: 0x%02x, ", __RX_frame.data.u8[5]);
printf("D6: 0x%02x, ", __RX_frame.data.u8[6]);
printf("D7: 0x%02x\n", __RX_frame.data.u8[7]);
printf("==============================================================================\n");
//loop back frame
// CAN_write_frame(&__RX_frame);
// } /* comment out if you use YOUR_CHOICE */
...
...
hope this helps
best wishes
rudi