Hi,
I'm working with a TM4C129ENCPDT microcontroller connected to external flash memory via SPI2. The connections are correct since it works when I use TI-RTOS. However, when I configure it without TI-RTOS, I can send data but I'm unable to read from the flash; it always shows 0. Here's my code. Can you please help me resolve this issue?
#include "inc/hw_memmap.h"
#include "inc/hw_nvic.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/interrupt.h"
#include "driverlib/eeprom.h"
#include "inc/tm4c129encpdt.h"
#include "inc/hw_types.h"
#include "inc/hw_nvic.h"
#include "driverlib/gpio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_flash.h"
#include "inc/hw_nvic.h"
#include "driverlib/ssi.h"
void main(void)
{
ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_OSC), 16000000);
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
//
// Enable clocks to GPIO Port D and configure pins as SSI
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinConfigure(GPIO_PD3_SSI2CLK);
GPIOPinConfigure(GPIO_PD2_SSI2FSS);
GPIOPinConfigure(GPIO_PD1_SSI2XDAT0);
GPIOPinConfigure(GPIO_PD0_SSI2XDAT1);
GPIOPinTypeSSI(GPIO_PORTD_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3));
SSIConfigSetExpClk(SSI_BASE_ADDR, ui32SysClock, SSI_FRF_MOTO_MODE_3, SSI_MODE_MASTER, 1000000, 8);
// Enable the SSI module.
SSIEnable(SSI_BASE_ADDR);
SSIAdvModeSet(SSI_BASE_ADDR, SSI_ADV_MODE_READ_WRITE);
SSIAdvFrameHoldDisable(SSI_BASE_ADDR);
//
// Read any residual data from the SSI port. This makes sure the receive
// FIFOs are empty, so we don't read any unwanted junk. This is done here
// because the SPI SSI mode is full-duplex, which allows you to send and
// receive at the same time. The SSIDataGetNonBlocking function returns
// "true" when data was returned, and "false" when no data was returned.
// The "non-blocking" function checks if there is any data in the receive
// FIFO and does not "hang" if there isn't.
//
uint32_t junk;
while(SSIDataGetNonBlocking(SSI_BASE_ADDR, &junk));
readDeviceID();
}
uint8_t spiSendReceiveByte(const uint8_t dataTx)
{
// Remove any residual or old data from the receive FIFO
uint32_t junk;
while (SSIDataGetNonBlocking(SSI_BASE_ADDR, &junk));
// SSI TX & RX
uint8_t dataRx[2];
SSIDataPut(SSI_BASE_ADDR, (uint32_t) dataTx);
// Wait until the transmit buffer is not full
while(SSIBusy(SSI_BASE_ADDR));
SSIDataGet(SSI_BASE_ADDR, (uint32_t *) &dataRx);
return dataRx[0];
}
uint8_t readDeviceID(void)
{
uint8_t DeviceID = 0;
DeviceID = spiSendReceiveByte(W25Q32JV_COMMAND_JEDEC_ID);
return DeviceID;
}
Based on the provided code, it seems that SSIDataGet() is setting the dataRX to 0.
Do I need to use DMA for this? If so, could you please provide guidance on how to configure it?
Regards,
Sony