麻烦大家帮忙看看,我使用TI TM4C123系列产品,SPI程序如下:
void SPIInit(uint32_t ui32Base, uint32_t ui32Clock, uint32_t ui32BitRate)
{
SPIGPIOInit();
//
// Configure the SPI module.
//
MAP_SSIConfigSetExpClk(SSI3_BASE, ROM_SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
SSI_MODE_MASTER,1000000, 8);
//
// Enable the advanced mode of operation, defaulting to read/write mode.
//
MAP_SSIAdvModeSet(SSI3_BASE, SSI_ADV_MODE_READ_WRITE);
//
// Enable the frame hold feature.
//
MAP_SSIAdvFrameHoldEnable(SSI3_BASE);
//
// Enable the SPI module.
//
MAP_SSIEnable(SSI3_BASE);
}
void SPIRead(uint32_t ui32Addr, uint8_t *pui8Data,
uint32_t ui32Count)
{
uint32_t ui32Trash;
//
// Drain any residual data from the receive FIFO.
//
while(MAP_SSIDataGetNonBlocking(SSI3_BASE, &ui32Trash) != 0)
{
}
//
// Set the SSI module into write-only mode.
//
MAP_SSIAdvModeSet(SSI3_BASE, SSI_ADV_MODE_WRITE);
//
// Send the read command.
//
MAP_SSIDataPut(SSI3_BASE, CMD_READ);
//
// Send the address of the first byte to read.
//
MAP_SSIDataPut(SSI3_BASE, (ui32Addr >> 8) & 0xff);
MAP_SSIDataPut(SSI3_BASE, ui32Addr & 0xff);
//
// Set the SSI module into read/write mode. In this mode, dummy writes are
// required in order to make the transfer occur; the SPI flash will ignore
// the data.
//
MAP_SSIAdvModeSet(SSI3_BASE, SSI_ADV_MODE_READ_WRITE);
//
// See if there is a single byte to be read.
//
if(ui32Count == 1)
{
//
// Perform a single dummy write, marking it as the end of the frame.
//
MAP_SSIAdvDataPutFrameEnd(SSI3_BASE, 0);
}
else
{
//
// Perform a dummy write to prime the loop.
//
MAP_SSIDataPut(SSI3_BASE, 0);
//
// Loop while there is more than one byte left to be read.
//
while(--ui32Count != 1)
{
//
// Perform a dummy write to keep the transmit FIFO from going
// empty.
//
MAP_SSIDataPut(SSI3_BASE, 0);
//
// Read the next data byte from the receive FIFO and place it into
// the data buffer.
//
MAP_SSIDataGet(SSI3_BASE, &ui32Addr);
*pui8Data++ = ui32Addr & 0xff;
}
//
// Perform the final dummy write, marking it as the end of the frame.
//
MAP_SSIAdvDataPutFrameEnd(SSI3_BASE, 0);
//
// Read the next data byte from the receive FIFO and place it into the
// data buffer.
//
MAP_SSIDataGet(SSI3_BASE, &ui32Addr);
*pui8Data++ = ui32Addr & 0xff;
}
//
// Read the final data byte from the receive FIFO and place it into the
// data buffer.
//
MAP_SSIDataGet(SSI3_BASE, &ui32Addr);
*pui8Data++ = ui32Addr & 0xff;
}
用示波器测试信号,写,时钟和片选信号均正常,EEPROM的输出无信号,一直为0.我使用的EEPROM型号
是25LC512.
麻烦各位大侠了!
此帖出自
小平头技术问答
参考 StellarisWareexamplesperipheralsssi 下的 spi_master.c 这个例程试试
一周热门 更多>