Other Parts Discussed in Thread: HALCOGEN
Hello,
I am a newbie who really wants to learn developing embedded applications. I have a TMS570LS launchpad and i am trying to communicate with launchpad through peakCAN. My application requirement is this; it should be able to receive a message with ID 0x34, light the LEDs according to the first byte of the message i'll receive, read the state of the LEDs and transmit a message back to the network indicating the state of the LEDs.
My HalCoGEN configuration;
I have configured message box 2 as transmit with the ID of 0x36 and box 3 as receive with 0x34.
My code;
main;
#include "can_practice2.h" #include "Device.h" #include "sys_core.h" int main(void) { canConfgInit(); for (;;) { canGetFrame(); lightLED(); readStateLED(); wait(100); sendStateLED(); } }
can application;
/* * can_practice2.c * * Created on: 17 Haz 2019 * Author: user */ #include "sys_common.h" #include "system.h" #include "gio.h" // Device Headers // #include "can.h" #include "esm.h" #include "Device.h" #include "can_practice2.h" uint8 LED_Requests[8] = {0,0,0,0,0,0,0,0}; // Assign an initial value to the to be received input uint8 StateLED1 = 0; // Assign the initial value of state of the LED 1 zero uint8 StateLED2 = 0; // Assign the initial value of state of the LED 1 zero uint8 CAN_TX_Message[8] = {0}; // Create an transmit array of zeros uint8 *rx_ptr = &LED_Requests[0]; void canConfgInit(void) { deviceInit(); // Initiate GIO & CAN setBitDirection(gioPORTA,0,1U); // GPIO 0 set as output setBitDirection(gioPORTA,1,1U); // GPIO 1 set as output } void canGetFrame(void) { //while(!canIsRxMessageArrived(canREG1, canMESSAGE_BOX2)); canGetData(canREG1,canMESSAGE_BOX3,rx_ptr); // Read the CAN message box 2 and write it to the address of LED_Requests } void lightLED(void) { switch (LED_Requests[0]) { case 0: gioSetBit(gioPORTA,0,0U); gioSetBit(gioPORTA,1,0U); break; case 1: gioSetBit(gioPORTA,0,1U); gioSetBit(gioPORTA,1,0U); break; case 2: gioSetBit(gioPORTA,0,0U); gioSetBit(gioPORTA,1,1U); break; case 3: gioSetBit(gioPORTA,0,1U); gioSetBit(gioPORTA,1,1U); break; } } void readStateLED (void) { StateLED1 = gioGetBit(gioPORTA,0); StateLED2 = gioGetBit(gioPORTA,1); } void sendStateLED (void) { CAN_TX_Message[0] = StateLED1; CAN_TX_Message[7] = StateLED2; canTransmit(canREG1,canMESSAGE_BOX2,&CAN_TX_Message); }
But this doesn't work. Code compiles successfully, LEDs light when i change the initial values from the array itself, LEDs states can be read and transmitted over CAN but receive is not happening. When i debug the canGetData function itself, i see it moves forward but when i uncomment while(!canIsRxMessageArrived) program stucks there, indicating message box is not receiving anything. Where i am doing wrong ? As i said i am a newbie and any help would be highly appreciated. Thank you.