Tool/software: TI C/C++ Compiler
Hi All,
I am using MSP430F5328 controller, trying to communicate with Winbound Serial Flash (W25X10CL) using SPI.
I have configured the SPI Init and trying to read the Device ID but not receiving anything.
Below is my intialization:
#define SPICLK 500000
int main()
{
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
);
IDcode = W25X10_ReadID();
return 0;
}
void W25X10_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 W25X10_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++;
}
}
uint16_t W25X10_ReadID(void)
{
uint16_t IDcode;
W25X10_CS0(); // P2.6 -- 0, CS = 0 Select SPI Flash
w25srcaddr[0] = 0x90; // Read device commands 0x90
w25srcaddr[1] = 0x00; // The upper part of the device address 0x00
w25srcaddr[2] = 0x00; // The lower part of the device address 0x00
w25srcaddr[3] = 0x00;
W25X10_SendData ( (uint8_t *)&w25srcaddr[0], 4 ); // SSP send data
W25X10_RcvData( (uint8_t *)&w25destaddr[0], 2 ); // SSP Receive data
W25X10_CS1(); // P2.6 -- 1, CS = 1 Release the SPI Flash
IDcode = (w25destaddr[0] << 8)|(w25destaddr[1]); // Get the IDcode
return IDcode; // Returns the ID number
}
Does anyone know why i am not receiving data on UCA0RXBUF & what mistake i am doing ?
Thanks for any help.