Hello, I'm running tirtos_2_10_01_38 on a Tiva TM4C123AE6PMI processor and having problems with SPI_transfer() crashing. I'm using SPI0, SPI1 and SPI2 for my application. Currently communications to I/O expanders on SPI1 and SPI2 seem to work fine. However, I have a write only TLV5637 DAC on SPI0 that I'm trying to write to that crashes when I call SPI_transfer().
I get the following message in the output console when it crashes.
[CORTEX_M4_0] MainPollTask()
ti.sysbios.knl.Semaphore: line 202: assertion failure: A_badContext: bad calling context. Must be called from a Task.
xdc.runtime.Error.raise: terminating execution
My code to write to the DAC is listed below. I'm fairly new to TI-RTOS and any help would be greatly appreciated!
Regards,
Bob
static SPI_Handle g_handleSpi0 = 0;
//*****************************************************************************
// Initialize and open various system peripherals we'll be using
//*****************************************************************************
void MotorDAC_initialize(void)
{
SPI_Params spiParams;
/* Open SSI-0 to the TLV5637 DAC motor drive amp driver */
/* Moto fmt, polarity 1, phase 0 */
SPI_Params_init(&spiParams);
spiParams.transferMode = SPI_MODE_BLOCKING;
spiParams.mode = SPI_MASTER;
spiParams.frameFormat = SPI_POL1_PHA0;
spiParams.bitRate = 1000000;
spiParams.dataSize = 8;
g_handleSpi0 = SPI_open(Board_SPI0, &spiParams);
if (g_handleSpi0 == NULL)
System_abort("Error initializing SPI0\n");
/* Set the torque to zero on reel motors! */
MotorDAC_write(0, 0);
}
//*****************************************************************************
// This function writes the takeup and supply motor DAC values controlling
// the motor drive amp. The TLV5637 is a dual 10-bit, single supply DAC,
// based on a resistor string architecture. The output voltage (full scale
// determined by reference) is given by:
//
// Vout = (2 REF) * (CODE/0x1000)
//
// Where REF is the reference voltage and CODE is the digital
// input value in the range 0x000 to 0xFFF. Because it is a
// 10-bit DAC, only D11 to D2 are used. D0 and D1 are ignored.
// A power-on reset initially puts the internal latches to a
// defined state (all bits zero).
//
// The motor current amp delivers full torque at 1mA and
// zero torque at 5.1mA.
//
// DAC A - is the SUPPLY motor torque level
// DAC B - is the TAKEUP motor torque level
//
//*****************************************************************************
void MotorDAC_write(uint32_t supply, uint32_t takeup)
{
uint16_t ulWord;
uint16_t ulReply;
uint16_t ulDac;
bool transferOK;
SPI_Transaction transaction;
/* DEBUG - save current values */
g_servo.dac_supply = supply;
g_servo.dac_takeup = takeup;
takeup = DAC_MAX - takeup;
supply = DAC_MAX - supply;
/* (1) Set reference voltage to 1.024 V (CONTROL register) */
ulWord = (1 << 15) | (1 << 12) | 0x01;
transaction.count = sizeof(ulWord);
transaction.txBuf = (Ptr)&ulWord;
transaction.rxBuf = (Ptr)&ulReply;
GPIO_write(Board_CS_SPI0, PIN_LOW);
transferOK = SPI_transfer(g_handleSpi0, &transaction);
GPIO_write(Board_CS_SPI0, PIN_HIGH);
/* (2) Write data for DAC B to BUFFER */
ulDac = (takeup & 0x3FF) << 2;
ulWord = (1 << 12) | (uint16_t)ulDac;
transaction.count = sizeof(ulWord);
transaction.txBuf = (Ptr)&ulWord;
transaction.rxBuf = (Ptr)&ulReply;
GPIO_write(Board_CS_SPI0, PIN_LOW);
transferOK = SPI_transfer(g_handleSpi0, &transaction);
GPIO_write(Board_CS_SPI0, PIN_HIGH);
/* (3) Write DAC A value and update DAC A & B simultaneously */
ulDac = (supply & 0x3FF) << 2;
ulWord = (1 << 15) | (uint16_t)ulDac;
transaction.count = sizeof(ulWord);
transaction.txBuf = (Ptr)&ulWord;
transaction.rxBuf = (Ptr)&ulReply;
GPIO_write(Board_CS_SPI0, PIN_LOW);
transferOK = SPI_transfer(g_handleSpi0, &transaction);
GPIO_write(Board_CS_SPI0, PIN_HIGH);
}