This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-F28379D: LAUNCHXL-F28379D

Part Number: LAUNCHXL-F28379D


Tool/software:

Hello Team, 

I am working with the LAUNCHXL-F28379D, in which i am currently working on CAN communication. where, i have no problem in establishing communication. Whereas, I have problem in dealing with ADCIN data. I want to communicate the data from the gpio pins present on the board to the central computer through CAN. 

I have transmitted the data from digital gpio pins successfully, but data from the adc pins is an issue for me. I need assistance regarding the data transmission corresponding to the ADCIN pins. 

I am attaching the syntax i am using for ADCIN pins. 

//
// Included Files
//
#include "device.h"
#include "driverlib.h"
#include "F28x_Project.h" // DSP28x Headerfile


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define TX_MSG_OBJ_ID 1
#define MSG_DATA_LENGTH 8

//
// Function to sample ADC data
//
int16_t sampleADC(void)
{
int16_t sample;

//
// Force start of conversion on SOC0
//
AdcaRegs.ADCSOCFRC1.all = 0x01;

//
// Wait for end of conversion
//
while(AdcaRegs.ADCINTFLG.bit.ADCINT1 == 0)
{
// Wait for ADCINT1
}
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Clear ADCINT1

//
// Get ADC sample result from SOC0
//
sample = AdcaResultRegs.ADCRESULT0;

return sample;
}

//
// Function to initialize ADC
//
void initializeADC(void)
{
EALLOW;

//
// Configure ADC Clock Prescaler
//
AdcaRegs.ADCCTL2.bit.PRESCALE = 6;

//
// Set ADC resolution and signal mode
//
AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);

//
// Set pulse positions to late
//
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;

//
// Power up the ADC
//
AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;

//
// Delay for 1ms to allow ADC to power up
//
DEVICE_DELAY_US(1000);

//
// Configure SOC0 to sample ADCIN14
//
AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0x0E; // SOC0 will convert pin ADCIN14
AdcaRegs.ADCSOC0CTL.bit.ACQPS = 25; // Sample window is 25+1 SYSCLK cycles

//
// Configure interrupt for SOC0
//
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0; // End of SOC0 will set INT1 flag
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; // Enable INT1 flag
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Clear INT1 flag

EDIS;
}

//
// Function to check CAN Status
//
void checkCANStatus(void)
{
uint16_t canStatus = HWREGH(CANB_BASE + CAN_O_ES);

if (canStatus & CAN_ES_BOFF)
{
// Handle bus-off error
}
if (canStatus & CAN_ES_EPASS)
{
// Handle error passive condition
}
if (canStatus & CAN_ES_EWARN)
{
// Handle error warning condition
}
}

//
// Main Function
//
void main(void)
{
//
// Initialize device and peripherals
//
Device_init();
Device_initGPIO();

//
// Configure GPIO for CAN
//
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXB);
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXB);

//
// Initialize ADC
//
initializeADC();


//
// Initialize CAN module
//
CAN_initModule(CANB_BASE);
CAN_setBitRate(CANB_BASE, DEVICE_SYSCLK_FREQ, 250000, 16);

//
// Configure CAN Message Object
//
CAN_setupMessageObject(CANB_BASE, TX_MSG_OBJ_ID, 0x181,
CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_TX, 0,
CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);

//
// Start CAN module
//
CAN_startModule(CANB_BASE);

while (1)
{
//
// Get ADC sample
//
int16_t adcData = sampleADC();

//
// Prepare CAN message data
//
uint16_t txMsgData_1[8] = {0};
txMsgData_1[0] = (uint16_t)(adcData & 0xFF); // Lower 8 bits of ADC data
txMsgData_1[1] = (uint16_t)((adcData >> 8) & 0xFF); // Upper 8 bits of ADC data

//
// Send ADC data via CAN
//
CAN_sendMessage(CANB_BASE, TX_MSG_OBJ_ID, MSG_DATA_LENGTH, txMsgData_1);


while (((HWREGH(CANB_BASE + CAN_O_ES) & CAN_ES_TXOK)) == CAN_ES_TXOK)
{
}


DEVICE_DELAY_US(500000);
}
}

Any kind of assistance will be highly helpful. 

Regards

Gourav

  • Hello Gourav,

    About this issue, I have a few thoughts for you to consider:
    First off, the message data array is 8 bytes, but only two bytes are filled in. This mismatch could lead to problems if the receiver is expecting the full 8-byte message to create the flag in the code.

    Also, the ADC value is being cast to uint16_t, which isn’t really needed since it’s already 16-bit. If the ADC result is actually a 12-bit value, can you pack it into the 12-bit CAN message?
    Lastly, the delay (DEVICE_DELAY_US(500000);) in the while loop comes after the transmission check. This could lead to inconsistent transmission intervals if the loop gets stuck. It’d be better to place the delay outside of any potential blocking situations.

    Best Regards,

    Masoud

  • Hello Masoud, 

    Thanks for the help but i already figured it out myself. did some tinkering and did it. 

    Regards.

  • Glad to hear the issue has solved! Let us know what was the origin of issue.

    Best Regards,

    Masoud

  • It was some linking errors. Just added some delays in adc initialization and CAN transmission, that removed the errors and also i added some configurations manually in the can.h file.