Forums

MSP430 SPI to EEPROM

Started by blas...@hotmail.com February 26, 2011
Hello, I'm currently trying to interface my MSP430F248 with a CAT25256 EEPROM. Right now I'm attempting set the WEL (Write enable) bit on the EEPROM by sending the appropriate command. I load the command onto UCA0TXBUF and set the CS bit to start the transfer.

According to the EEPROM datasheet, the MISO pin should be at high impedance while WEL is being set. I'm assuming since I'm not receiving anything on the UCA0RXBUF then it is not transmitting either. Its my first time attempting SPI, I hope you all can help me find errors!

The code I have is below:

#include

#define WR_EN 6
#define WR_DI 4
#define RD_SR 5
#define WR_SR 1
#define READ 3
#define WRITE 2

void MemWrite(unsigned char);

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;

P3SEL |= 0x31; // P3.0,4,5 USCI_A0 option select
P3DIR |= 0x08; // P3.3 Chip Select

UCA0CTL1 |= UCSWRST;
UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master, Mode (0,0)
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 |= 0x02;
UCA0BR1 = 0;
UCA0MCTL = 0;
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**

MemWrite(0xAF);
}

void MemWrite(unsigned char data)
{
// Setting WEL bit on EEPROM by sending write enable cmd.
while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = WR_EN; // EEPROM Write Enable Cmd
P3OUT &= ~0x08; // Enable CS
while(!(IFG2 & UCA0RXIFG)); // Wait for RX complete
P3OUT |= 0x08; // Disable CS
IFG2 &= ~UCA0RXIFG; // Clear flag

// Read EEPROM status register to ensure WEL bit is set
while(!(IFG2 & UCA0TXIFG)); // Wait for TX Rdy
UCA0TXBUF = RD_SR; // EEPROM Read Status Cmd
P3OUT &= ~0x08; // Enable CS
while(!(IFG2 & UCA0RXIFG));
P3OUT |= 0x08;
IFG2 &= ~UCA0RXIFG;
}

Beginning Microcontrollers with the MSP430