Francesco Masciari
/
can_multithreadingX_vesctest
A test for vescs
main.cpp
- Committer:
- gidiana
- Date:
- 2018-12-06
- Revision:
- 0:0da0fd430e20
- Child:
- 1:9ecda2b969c2
File content as of revision 0:0da0fd430e20:
#include "mbed.h" //5.4.7 (144) const PinName can1rxPins[] = {PA_11}; const PinName can1txPins[] = {PA_12}; const PinName can2rxPins[] = {PB_12}; const PinName can2txPins[] = {PB_13}; //CAN1 //0,0=OK 0,1=OK 0,2=OK 1,0=OK 1,1=OK 1,2=OK 2,0=OK 2,1=OK 2,2=OK //CAN2 //0,0=RX_OK 0,1=OK 1,0=RX_OK 1,1=OK CAN can1(can1rxPins[0], can1txPins[0]); CAN can(can2rxPins[0], can2txPins[0]); //UART1, Tx, Rx (Debug) DigitalOut led1(LED1); Thread sendThread(osPriorityAboveNormal, 2048); Thread canrx; CANMessage messageIn; CANMessage messageOut; void canRxIsr() { while(1) { if(can1.read(messageIn)) { led1 = !led1; printf("received\n\r"); } } } void sendMessage() { int status = can.write(messageOut); printf("Send status: %d\r\n", status); } void sendMessageLoop() { while (true) { sendMessage(); osDelay(1000); } } int main() { printf("CAN receive / transmit test.\r\n"); //can.frequency(125000); messageOut.id = 1337; //messageOut.format = CANExtended; //messageOut.len = 0; canrx.start(canRxIsr); printf("CAN receive / .\r\n"); sendThread.start(&sendMessageLoop); printf("CAN \r\n"); while (true) { led1 = 0; osDelay(1000); } }