Other Parts Discussed in Thread: CC2541
Hi,
I'm interfacing the CC2541 as a master with the ADXL362 accelerometer as a slave over SPI. However, I'm stuck at the very first step which is sending a 'read' command.
The accelerometer connects to the CC2541 through port 0's USART in alternative 1 as illustrated in this diagram.
As you can see, a GPIO pin (P0.6) will act as CS which is expected by the accelerometer
I have this declarations on my project
INT_HEAP_LEN=3072 HALNODEBUG OSAL_CBTIMER_NUM_TASKS=1 HAL_AES_DMA=TRUE HAL_DMA=TRUE POWER_SAVING xPLUS_BROADCASTER HAL_LCD=FALSE HAL_LED=TRUE HAL_UART_SPI=1 HAL_SPI_MASTER
and I'm calling this function from within InitBoard() in OnBoard.c:
void InitAccelerometer (void)
{
halUARTCfg_t uartConfig;
// Create buffers to write the command and to receive the device's ID
uint8 id[1];
uint8 command[] =
{
ADXL_READ_REG, // Send (or write) 'READ REGISTER' command 0x0B
DEVID_AD // append register´s address 0x00
};
uartConfig.callBackFunc = AccelerometerCallback; // Set up a callback function to receive events
HalUARTOpen(HAL_UART_PORT_0, &uartConfig);
P0_6 = 0; // Drive CS down to enable acceleromter
HalUARTWrite(HAL_UART_PORT_0, command, 2); // Send 'read' commmand to sensor along with the address of the register to be read (2 bytes)
HalUARTRead(HAL_UART_PORT_0, id, 1); // Read the response from the sensor
P0_6 = 1; // Disable accelerometer
}
The problem is that once the writing the SPI command is done, the program execution loops indefinitely in the second 'while(SPI_RDY_IN())' loop of this function:
void HalUART_DMAIsrSPI(void)
{
#if defined HAL_SPI_MASTER
/* SPI Master must hold CSn active until Tx flushes */
while (UxCSR & CSR_ACTIVE);
while(SPI_RDY_IN())
{
SPI_CLOCK_RX(1);
}
#else
spiRdyIsr = 0;
#endif
UxDBUF = 0x00; /* Clear the garbage */
SPI_CLR_RDY_OUT(); /* SPI_RDYOut = 1 */
spiTxLen = 0;
}
I've tried to find documentation on this matter but this subject is quite limited and usually all info is about using SPI to interface to another microcontroller as a slave via HCI or NPI. My understanding is that I don't need either of those since I'm connecting to a simple peripheral to read sensor data so most docs are not appropriate to my application.
I really don't know what I'm doing, so any comments would be quite useful. Maybe I missed configuring something about DMA or ISR and that's why I'm stuck in that loop?
