Other Parts Discussed in Thread: MSP430F5529
Hello!
I'm hoping someone will be able to point me in the right direction. I'm working on getting my MSP430F5529 to read the device ID from a WinBond Flash device. At this point, I am able to successfully send the command to read the device ID and have the flash chip reply properly (I have verified this with a signal analyzer).
My issue however, is that the device ID and manufacturer ID always return 0. Any idea why the MSP would be confused about what value is coming into SOMI when electrically the right bits are on the line?
Here is my code:
uint08 ManufacturerID = 2;
uint08 DeviceID = 2;
void main(void)
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
Powerup();
SPI_Enable(TRUE);
//select a flash chip to read, pull down CS line.
FLASH_FlashSelect(1);
//read the device ID
retval = DLPCFLASH_GetFlashID(&ManufacturerID, &DeviceID);
//close SPI communication, release CS line.
FLASH_FlashSelect(0);
}
void SPI_Enable (BOOL Enable)
{
if (Enable)
{
// SPI clk configuration
GPIO_SetBits(&P2SEL, SPICLK_MSP);
// SPI Data configuration
P3SEL |= SPIDOUT_MSP + SPIDIN_MSP;
// Reset USCI
UCA0CTL1 |= UCSWRST;
// Configure 3 pin, 8-bit SPI master operation
SPI_ClockMode (SPI_MODE_1); //use SPI_MODE_1 for proper operation.
UCA0CTL0 |= UCMST + UCSYNC + UCMSB; //master mode, synchronous, MSB first
UCA0CTL1 |= UCSSEL_2; //SMCLK
UCA0BR0 = 0; // No frequency division
UCA0BR1 = 0;
UCA0MCTL = 0; // No modulation
GPIO_ClearBits(&UCA0CTL1, UCSWRST); // Re initialize USCI
}
else
{
GPIO_ClearBits(&P2SEL, SPICLK_MSP); // Configure as GPIO
GPIO_ClearBits(&P2DIR, SPICLK_MSP); // Configure P2 as Input
}
}
int08 DLPCFLASH_GetFlashID (uint08 *ManufacturerID, uint08 *DeviceID)
{
const uint08 ReadLength = 2, WriteLength = 4;
uint08 TxData[4];
uint08 RxData[2];
TxData[0] = FLASH_CMD_GET_MANUFACTURER_ID;
TxData[1] = SPI_DUMMY_BYTE;
TxData[2] = SPI_DUMMY_BYTE;
TxData[3] = SPI_DUMMY_BYTE;
if (SPI_SendReceiveData (RxData, TxData, ReadLength, WriteLength) != PASS)
{
return FAIL;
}
*ManufacturerID = RxData[0];
*DeviceID = RxData[1];
return PASS;
}
int08 SPI_SendReceiveData (uint08 *ReadData, uint08 *WriteData,
uint16 ReadLength, uint16 WriteLength)
{
int i = 0, j = 0;
uint16 MaxLength = WriteLength;
TxData = WriteData;
RxData = ReadData;
BytesRead = 0;
for (j = 0; j < MaxLength; j++)
{
i = 0;
while (!(UCA0IFG & UCTXIFG)); // While TX buffer not ready
{
if (i > 100)
{
STS_SetStatus (STS_SPI_BUS_BUSY);
return FAIL;
}
i++;
}
UCA0TXBUF = TxData[j];
_delay_cycles (SPI_WRITE_DELAY_CYCLES); // Add time between transmissions to make sure slave can process information
}
for (j = 0; j < ReadLength; j++)
{
UCA0TXBUF = (SPI_DUMMY_BYTE); // Send dummy byte to trigger reading data
RxData[j] = UCA0RXBUF; // Synchronously read data from slave
}
return PASS;
}
For reference, here is a screen grab of the signal analyzer:
Thanks,
Paul
