Quantcast
Viewing all articles
Browse latest Browse all 63778

Forum Post: RE: MSP430F5529 SPI not receiving data

Caleb, Thanks for the help. I've cleaned up the code, so now all should be clear: uint08 ManufacturerID = 2; uint08 DeviceID = 2; uint08 retval = 0; void main(void) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; //init ports. P2SEL = 0; P2OUT = 0; P3OUT |= 0; P3SEL |= 0; //power up the regulators on the board. Enable SPI 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 P2SEL |= SPICLK_MSP; //BIT7 // SPI Data configuration P3SEL |= SPIDOUT_MSP + SPIDIN_MSP; //BIT3 + BIT4 // Reset USCI UCA0CTL1 |= UCSWRST; // Configure 3 pin, 8-bit SPI master operation UCA0CTL0 |= UCMST + UCSYNC + UCMSB + UCCKPH; //master mode, synchronous, MSB first UCA0CTL1 |= UCSSEL_2; //SMCLK UCA0BR0 = 0; // No frequency division UCA0BR1 = 0; UCA0MCTL = 0; // No modulation UCA0CTL1 &= ~UCSWRST; // Re-initialize USCI } else { P2SEL &= ~SPICLK_MSP; // Configure as GPIO, BIT7 P2DIR &= ~SPICLK_MSP; // Configure as Input, BIT7 } } 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; //0x00, could be 0xFF 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 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++) { while(!(UCA0IFG & UCTXIFG)); //while TX buffer not ready. UCA0TXBUF = (SPI_DUMMY_BYTE); // Send dummy byte to trigger reading data while(!(UCA0IFG & UCRXIFG)); //while TX buffer not ready. RxData[j] = UCA0RXBUF; // Synchronously read data from slave } return PASS; } Let me know if you have any more questions. Paul

Viewing all articles
Browse latest Browse all 63778

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>