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