Tool/software: TI C/C++ Compiler
Hi,
I am using MSP430F5328 interface with W25X10 winbound serial flash using SPI communication protocol. I am using SMCLK 16MHz.
I have configure SPI based on the slave device & source code as below:
#define SPICLK 32
uint8_t SourceAddr [16];
uint8_t DestAddr[16];
void main( void )
{
uint16_t IDcode = 0;
//Set P2.6 for slave reset
GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN6 );
GPIO_setOutputHighOnPin( GPIO_PORT_P2, GPIO_PIN6 );
//P3.3,4 option select
//FLASH_SPISIMO - P3.3
//FLASH_SPISOMI - P3.4
GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P3, GPIO_PIN3 + GPIO_PIN4 );
//P2.7 FLASH_SPICLK
GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P2, GPIO_PIN7);
//Initialize Master
USCI_A_SPI_initMasterParam param = {0};
param.selectClockSource = USCI_A_SPI_CLOCKSOURCE_SMCLK;
param.clockSourceFrequency = UCS_getSMCLK();
param.desiredSpiClock = SPICLK;
param.msbFirst = USCI_A_SPI_MSB_FIRST;
param.clockPhase = USCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT;
param.clockPolarity = USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW;
returnValue = USCI_A_SPI_initMaster(USCI_A0_BASE, ¶m);
if (STATUS_FAIL == returnValue)
return 0;
//Enable SPI module
USCI_A_SPI_enable(USCI_A0_BASE);
//Now with SPI signals initialized, reset slave
GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN6 );
/* Reading Manufacturer ID */
IDcode =
SerialFlash_ReadID();
}
uint16_t SerialFlash_ReadID(void)
{
uint16_t IDcode;
// P2.6 -- 0, CS = 0 Select SPI Flash
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN6);
// Read device commands 0x90
SourceAddr[0] = 0x90;
// The upper part of the device address 0x00
SourceAddr[1] = 0x00;
// The lower part of the device address 0x00
SourceAddr[2] = 0x00;
SourceAddr[3] = 0x00;
// Serial Flash send data
SerialFlash_SendData ( (uint8_t *)&SourceAddr[0], 4 );
__delay_cycles(160000);
// Serial Flash Receive data
SerialFlash_RcvData( (uint8_t *)&DestAddr[0], 2 );
// P2.6 -- 1, CS = 1 Release the SPI Flash
GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN6);
// Get the IDcode
IDcode = (DestAddr[0] << 8)|(DestAddr[1]);
return IDcode;
}
void SerialFlash_SendData( uint8_t *buf, uint32_t Length )
{
uint32_t i;
for ( i = 0; i < Length; i++ )
{
// USCI_A0 TX buffer ready?
while (!(UCA0IFG&UCTXIFG));
UCA0TXBUF = *buf;
buf++;
}
}
void SerialFlash_RcvData( uint8_t *buf, uint32_t Length )
{
uint32_t i;
for ( i = 0; i < Length; i++ )
{
// USCI_A0 RX buffer ready?
while (!(UCA0IFG&UCRXIFG));
*buf = USCI_A_SPI_receiveData(USCI_A0_BASE);
buf++;
}
}
I have checked MOSI & Clock signal on Oscilloscope and getting perfectly.
but i am not able to read Manufacturer ID correctly on receiver buffer. Most of the time getting 0xFF, 0xFF or sometimes getting some random values.
Could anyone please help me figure out the issue.
Thanks & Regards,
John