Other Parts Discussed in Thread: MSP430F248
2/28/11 - Updated code in reply below
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's status register by sending the appropriate command. I enable the EEPROM by setting CS low and then load the command (WR_EN) into UCA0TXBUF. Then I do the same with RD_SR, which attempts to read the EEPROM status register.
I'm assuming since I'm not receiving anything on the UCA0RXBUF then it is not transmitting either. Its my first time attempting this MSP and SPI, so I'm not sure where I might have a mistake. Thanks for looking.
The code I have is below:
#include "msp430f248.h"
#define WR_EN 0x06
#define WR_DI 0x04
#define RD_SR 0x05
#define WR_SR 0x01
#define READ 0x03
#define WRITE 0x02
unsigned char temp;
void MemWrite(unsigned char);
unsigned char MemRead(unsigned char);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P3SEL |= 0x31; // P3.0,4,5 USCI_A0 option select
P3DIR |= 0x08; // P3.3 Chip select
P3OUT |= 0x08; // Disable EEPROM
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**
P3OUT &= ~0x08; // Enable EEPROM
MemWrite(WR_EN); // Write enable command
P3OUT |= 0x08; // Disable EEPROM
P3OUT &= ~0x08; // Enable EEPROM
MemWrite(RD_SR); // Read status Register of EEPROM to ensure WEL bit is set
MemWrite(0xAA); // Write dummy values to push EEPROM status into UCA0RXBUF
P3OUT |= 0x08; // Disable EEPROM
}
void MemWrite(unsigned char TXdata)
{
while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = TXdata;
while (!(IFG2 & UCA0RXIFG)); // USCI_A0 RX buffer ready?
temp = UCA0RXBUF;
IFG2 &= ~UCA0RXIFG;
}