Content originally posted in LPCWare by dvrose86 on Mon Jan 20 11:17:38 MST 2014
I am using the SSP0 module to communicate with a serial ee flash. My basic problem is in the SSP0DR read. I am always getting a 0. I am using the IAR 6.40 ewarm. I have a logic analyzer on the ssp bus and all the traffic looks good. Data is being sent to the device correctly, and data is being sent back by the device. Using the debugger watch I can see the correct data in the SS0DR but after a read the variable is 0. We made a mistake and are using a dedicated port pin for the Serial ee chip select instead of the SS of the SSP module. this works and can be viewed on the logic analyzer screen.
My init code looks like
void SSP_Init(void)
{
PCONP |= PCONP_SSP0; // power up SSP0
IOCON_P0_15 = 0x2; // SSP_CLK
IOCON_P0_17 = 0x2; //SSP_MISO
IOCON_P0_18 = 0x2; // SSP_MOSI
IOCON_P0_20 = (0x0<<0)|(0x1<<4)|(0x0<<5)|(0x0<<6)|(0x1<<9)|(0x0<<10); // Flash CS generial dio.
uc_dio_set(SPI_FLASH_CS); // Bring CS high
// uc_dio_clear(SPI_FLASH_CS);
// uc_dio_set(SPI_FLASH_CS);
SSP0CR0 = 0x000010c7; // divisor == 10h + chpa = 1 + cpol = 1 + 8 bit transfers
SSP0CR1 = 0x00000002; // not loopback + SSEnable enabled + SSE is a master
SSP0CPSR = 0x00000010;
}
the following code is the test call to query the manufacturer ID from the flash device.
void SSP_Test (void)
{
uint16_t status;
while (SSP0SR & SSP_SR_RNE ) // clear receive buffer..
status = SSP_ReceiveData();
CS_L // this just asserts the cs to the device and works fine
SSP_SendData(CMD_W25_MANUFACTURE_ID);
SSP_SendData(0x00); // address 00 msb 24 bits
SSP_SendData(0x00); // address 00 Middle address
SSP_SendData(0x00); // address 00 Low address
manufacturer_id = spi_write_read (0xff);
device_id = spi_write_read(0xff);
/*SSP_SendData(0xff); // needed for clock
while (SSP0SR & SSP_SR_RNE )
manufacturer_id = SSP_ReceiveData();
SSP_SendData(0xff); // needed for clock
while (SSP0SR & SSP_SR_RNE )
device_id = SSP_ReceiveData();*/
while (SSP0SR & SSP_SR_BSY ); // wait till not busy
CS_H // deasserts the CS to the device
}
Here is the code for the spi_write_read
uint8_t spi_write_read( uint8_t outgoing )
{
uint16_t incoming, dumb;
while( ( SSP0SR & 0x4 ) )
{
dumb = SSP0DR; // flush anything in the rx fifo as it is junk
}
while( !( SSP0SR & 0x02 ) ) { ; }
SSP0DR = outgoing; // operation used to generate clocks for the read
while( !( SSP0SR & 0x4 ) ){;} // while rx fifo empty wait
while( ( SSP0SR & 0x4 ) ) // while rx fifo has data read
{
incoming = SSP_ReceiveData();
}
the problem is that at the SSP_ReceiveData call I can see the SSP0DR via watch window has the correct data in it but returns a 0.
Here is the SSP_ReceiveData function.
uint16_t SSP_ReceiveData(void)
{
return ((uint16_t) (SSP_DR_BITMASK(SSP0DR)));
}
return incoming;
}
I have seen similar posts on this board which have indicated the same issue but cannot find a reply. Any help would be greatly appreciated.