Other Parts Discussed in Thread: CC2650, AFE4490
Tool/software: TI-RTOS
Hello,
I have been working on CC2650 Launchpad, i have been encountering an issue which i am unable to pinpoint the cause of.
I am using CC2650 to communicate with AFE4490 via SPI protocol. I have created a task function, where i have initialized all of the SPI parameters and also writing the default registers necessary to run AFE4490.
Now the issue arises, when i set an interrupt on RDY pin and the function afecallback is called. in this function, i am reading the registers for getting the ADC data. When i run the program, i encounter no errors but i am unable to get any data. So to verify whether the function was being called i used breakpoints. i placed breakpoints in the afecallback function and the program reaches there perfectly, which includes the writing of the registers and enabling of the read function for registers too. After proceeding the program using breakpoints, i saw that the breakpoint gets stuck inside the "for" and "if" loop (as shown in the image highlighted in Blue color). Also below is my program. please revert as soon as possible.
/*
* ======== empty.c ========
*/
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>
#include <ti/drivers/pin/PINCC26XX.h>
#include <ti/drivers/SPI.h>
#include <ti/drivers/UART.h>
/* Board Header files */
#include "Board.h"
#define TASKSTACKSIZE 1024
Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];
/* Variables */
#define arraylength 2
#define data_length 6
uint8_t txBuf[arraylength*2];
uint8_t rxBuf[arraylength*2];
uint8_t transferok;
uint8_t i=0;
uint32_t adcreading[data_length];
uint8_t RxBuffer[1];
uint8_t flag_alt = 1;
uint8_t flag = 0;
/* SPI driver Handles */
static SPI_Handle spiHandle;
static SPI_Params spiParams;
static SPI_Transaction transaction;
/* Pin driver handle */
static PIN_Handle pinHandle;
static PIN_State pinState;
/* Pin driver handles */
static PIN_Handle buttonPinHandle;
static PIN_Handle ledPinHandle;
/* Global memory storage for a PIN_Config table */
static PIN_State buttonPinState;
static PIN_State ledPinState;
PIN_Config pinTable[] =
{
AFE_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX, //csn pin
AFE_PDN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
AFE_RST | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
AFE_RDY | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_DIS, //PIN_IRQ_POSEDGE,
PIN_TERMINATE
};
/*
* Application LED pin configuration table:
* - All LEDs board LEDs are off.
*/
PIN_Config ledPinTable[] = {
Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};
/*
* Application button pin configuration table:
* - Buttons interrupts are configured to trigger on falling edge.
*/
PIN_Config buttonPinTable[] = {
Board_BUTTON0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
PIN_TERMINATE
};
/* Function Prototyping */
signed long AFE4490_reg_read (unsigned char Reg_address);
void AFE4490_reg_write (unsigned char reg_address, uint32_t data);
void spi_read(uint8_t reg_address, uint32_t* data);
void AFE4490_Reg_Init(void);
void read_enable(void);
void read_disable(void);
void afeCallbackFxn(PIN_Handle handle, PIN_Id pinId);
void UartApp_UartRxCB(UART_Handle handle, void *buf, size_t count);
void enable_pin_interrupt();
void disable_pin_interrupt();
//void Spi_Int_Callback(SPI_Handle handle, SPI_Transaction *objTransaction);
/*
* ======== buttonCallbackFxn ========
* Pin interrupt Callback function board buttons configured in the pinTable.
* If Board_LED3 and Board_LED4 are defined, then we'll add them to the PIN
* callback function.
*/
void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) {
uint32_t currVal = 0;
/* Debounce logic, only toggle if the button is still pushed (low) */
CPUdelay(8000*50);
if (!PIN_getInputValue(pinId)) {
/* Toggle LED based on the button pressed */
switch (pinId) {
case Board_BUTTON0:
currVal = PIN_getOutputValue(Board_LED1);
PIN_setOutputValue(ledPinHandle, Board_LED1, !currVal);
enable_pin_interrupt();
break;
default:
/* Do nothing */
break;
}
}
}
/*
* ======== heartBeatFxn ========
* Toggle the Board_LED1. The Task_sleep is determined by arg0 which
* is configured for the heartBeat Task instance.
*/
Void heartBeatFxn(UArg arg0, UArg arg1)
{
SPI_init();
// Init SPI and specify non-default parameters
SPI_Params_init(&spiParams);
spiParams.transferMode = SPI_MODE_BLOCKING;//SPI_MODE_CALLBACK;//
spiParams.bitRate = 2000000;
spiParams.dataSize = 8;
spiParams.frameFormat = SPI_POL0_PHA0;
spiParams.mode = SPI_MASTER;
spiParams.transferCallbackFxn = Spi_Int_Callback;
// Configure the transaction
transaction.count = sizeof(txBuf);
transaction.txBuf = (Ptr)txBuf;
transaction.rxBuf = (Ptr)rxBuf;
spiHandle = SPI_open(Board_SPI0, &spiParams);
PIN_setOutputValue(pinHandle, AFE_RST, 1);
PIN_setOutputValue(pinHandle, AFE_PDN, 1);
PIN_setOutputValue(pinHandle, AFE_RST, 0);
PIN_setOutputValue(pinHandle, AFE_RST, 1);
PIN_setOutputValue(pinHandle, AFE_CS, 1); // Set CSn high
AFE4490_Reg_Init();
read_enable();
/* Turn on tx LED */
// PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
}
/*
* ======== main ========
*/
int main(void)
{
Task_Params taskParams;
/* Call board init functions */
Board_initGeneral();
Board_initSPI();
/* Construct heartBeat Task thread */
Task_Params_init(&taskParams);
taskParams.arg0 = 1000000 / Clock_tickPeriod;
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);
/* Open LED pins */
ledPinHandle = PIN_open(&ledPinState, ledPinTable);
if(!ledPinHandle) {
System_abort("Error initializing board LED pins\n");
}
buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
if(!buttonPinHandle) {
System_abort("Error initializing button pins\n");
}
pinHandle = PIN_open(&pinState, pinTable);
if (pinHandle == NULL) {
while(1); /* Error Initializing the Pins Defined in "pintable" */
}
/* Setup callback for button pins */
if (PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn) != 0) {
System_abort("Error registering button callback function");
}
/* Setup callback for DRDY pin */
if (PIN_registerIntCb(pinHandle, &afeCallbackFxn) != 0)
{
/* Error registering button callback function */
while(1);
}
System_printf("Starting the example\nSystem provider is set to SysMin. "
"Halt the target to view any SysMin contents in ROV.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();
/* Start BIOS */
BIOS_start();
return (0);
}
/* ----------------------------------------------------------------------------------------- */
/* AFE Callback Function */
/* ----------------------------------------------------------------------------------------- */
//void Spi_Int_Callback(SPI_Handle handle, SPI_Transaction *objTransaction)
//{
//
// adcreading[5]=AFE4490_reg_read(0x2F); //LED1-ALED1 difference
//
//}
void afeCallbackFxn(PIN_Handle handle, PIN_Id pinId)
{
adcreading[0]=AFE4490_reg_read(0x2A); //LED2 red phase
adcreading[1]=AFE4490_reg_read(0x2B); //ALED2 red phase
adcreading[2]=AFE4490_reg_read(0x2C); //LED1 IR phase
adcreading[3]=AFE4490_reg_read(0x2D); //ALED1 IR phase
adcreading[4]=AFE4490_reg_read(0x2E); //LED2-ALED2 difference
adcreading[5]=AFE4490_reg_read(0x2F); //LED1-ALED1 difference
}
/* ----------------------------------------------------------------------------------------- */
/* SPI Register Write Function */
/* ----------------------------------------------------------------------------------------- */
void AFE4490_reg_write (unsigned char reg_address, uint32_t data)
{
txBuf[0] = ((uint32_t)reg_address);
txBuf[1] = data>>16;
txBuf[2] = data>>8;
txBuf[3] = data;
rxBuf[0] = 0;
rxBuf[1] = 0;
rxBuf[2] = 0;
rxBuf[3] = 0;
PIN_setOutputValue(pinHandle, AFE_CS, 0); // Set CSn low
SPI_transfer(spiHandle, &transaction);
PIN_setOutputValue(pinHandle, AFE_CS, 1); // Set CSn high
}
/* ----------------------------------------------------------------------------------------- */
/* SPI Read Function */
/* ----------------------------------------------------------------------------------------- */
void spi_read(uint8_t reg_address, uint32_t* data)
{
txBuf[0] = ((uint32_t)reg_address);
txBuf[1] = 0;
txBuf[2] = 0;
txBuf[3] = 0;
rxBuf[0] = 0;
rxBuf[1] = 0;
rxBuf[2] = 0;
rxBuf[3] = 0;
/* Initiate SPI transfer */
PIN_setOutputValue(pinHandle, AFE_CS, 0); // Set CSn low
transferok = SPI_transfer(spiHandle, &transaction);
PIN_setOutputValue(pinHandle, AFE_CS, 1); // Set CSn high
if(transferok)
{
*data = (rxBuf[1]<<16)|(rxBuf[2]<<8)|(rxBuf[3]);
}
else
{
*data = 0; //data is not valid
}
}
/* ----------------------------------------------------------------------------------------- */
/* AFE4490 Register Read Function */
/* ----------------------------------------------------------------------------------------- */
signed long AFE4490_reg_read (unsigned char Reg_address)
{
uint32_t configData;
unsigned long retVal;
spi_read(Reg_address, &configData);
retVal = configData;
return retVal ;
}
/* ----------------------------------------------------------------------------------------- */
/* AFE4420 SPI read enable and disable Function */
/* ----------------------------------------------------------------------------------------- */
void read_enable(void)
{
txBuf[0] = 0x00;
txBuf[1] = 0x00;
txBuf[2] = 0x00;
txBuf[3] = 0x01;
PIN_setOutputValue(pinHandle, AFE_CS, 0); // Set CSn low
SPI_transfer(spiHandle, &transaction);
PIN_setOutputValue(pinHandle, AFE_CS, 1); // Set CSn high
}
void read_disable(void)
{
txBuf[0] = 0x00;
txBuf[1] = 0x00;
txBuf[2] = 0x00;
txBuf[3] = 0x00;
PIN_setOutputValue(pinHandle, AFE_CS, 0); // Set CSn low
SPI_transfer(spiHandle, &transaction);
PIN_setOutputValue(pinHandle, AFE_CS, 1); // Set CSn high
}
/* ----------------------------------------------------------------------------------------- */
/* AFE4420 Register Initialization Function */
/* ----------------------------------------------------------------------------------------- */
void AFE4490_Reg_Init(void)
{
AFE4490_reg_write(0x01, 0x003AE8);
AFE4490_reg_write(0x02, 0x003CEE);
AFE4490_reg_write(0x03, 0x003A98);
AFE4490_reg_write(0x04, 0x004E1F);
AFE4490_reg_write(0x05, 0x000050);
AFE4490_reg_write(0x06, 0x000256);
AFE4490_reg_write(0x07, 0x0013D8);
AFE4490_reg_write(0x08, 0x0015DE);
AFE4490_reg_write(0x09, 0x001388);
AFE4490_reg_write(0x0A, 0x0015DF);
AFE4490_reg_write(0x0B, 0x002760);
AFE4490_reg_write(0x0C, 0x002966);
AFE4490_reg_write(0x0D, 0x000006);
AFE4490_reg_write(0x0E, 0x001387);
AFE4490_reg_write(0x0F, 0x00138E);
AFE4490_reg_write(0x10, 0x00270F);
AFE4490_reg_write(0x11, 0x002716);
AFE4490_reg_write(0x12, 0x003A97);
AFE4490_reg_write(0x13, 0x003A9E);
AFE4490_reg_write(0x14, 0x004E1F);
AFE4490_reg_write(0x15, 0x000000);
AFE4490_reg_write(0x16, 0x000005);
AFE4490_reg_write(0x17, 0x001388);
AFE4490_reg_write(0x18, 0x00138D);
AFE4490_reg_write(0x19, 0x002710);
AFE4490_reg_write(0x1A, 0x002715);
AFE4490_reg_write(0x1B, 0x003A98);
AFE4490_reg_write(0x1C, 0x003A9D);
AFE4490_reg_write(0x1D, 0x004E1F);
AFE4490_reg_write(0x1E, 0x000102);
AFE4490_reg_write(0x1F, 0x000000);
AFE4490_reg_write(0x20, 0x000000);
AFE4490_reg_write(0x21, 0x000000);
AFE4490_reg_write(0x22, 0x01FFFF);
AFE4490_reg_write(0x23, 0x020100);
AFE4490_reg_write(0x24, 0x000000);
AFE4490_reg_write(0x25, 0x000000);
AFE4490_reg_write(0x26, 0x000000);
AFE4490_reg_write(0x27, 0x000000);
AFE4490_reg_write(0x28, 0x000000);
AFE4490_reg_write(0x29, 0x000000);
AFE4490_reg_write(0x2A, 0x000000);
AFE4490_reg_write(0x2B, 0x000000);
AFE4490_reg_write(0x2C, 0x000000);
AFE4490_reg_write(0x2D, 0x000000);
AFE4490_reg_write(0x2E, 0x000000);
AFE4490_reg_write(0x2F, 0x000000);
AFE4490_reg_write(0x30, 0x000000);
}
void enable_pin_interrupt()
{
PIN_setInterrupt(pinHandle, AFE_RDY | PIN_IRQ_POSEDGE);
}
void disable_pin_interrupt()
{
PIN_setInterrupt(pinHandle, AFE_RDY | PIN_IRQ_DIS);
}

