Hi,
I am new to TI micro-controller's and I am having trouble communicating to external EEPROM (25AA1024) with the MSP430F2481. I have checked the hardware and cant see any issue's. More then likely its my code. I have posted the code below for reference. Any help or links to tutorials would be very appreciated. Thank you.
#include <msp430.h>
#include <eeprom.h>
void eeprom_init(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
__bis_SR_register(GIE);
// Set BCSCTL and DCOCTL for 16MHz operation
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
BCSCTL3 = XT2S_0 + LFXT1S_0 + XCAP_2;
// Iniitalise BCSTL2
BCSCTL2 = 0;
// Setup main clock
BCSCTL2 |= SELM_0; // Select DCO clk
BCSCTL2 |= DIVM_0; // 1:1 divider
// Setup Sub-main clock
BCSCTL2 |= DIVS_0; // 1:8 divider
P5DIR = 0x1b;
P5OUT = 0x19;
P5REN = 0xe0;
P5SEL = 0x0e;
LIS_SPI_DIR |= BIT3; // output.
LIS_SPI_DIR |= BIT1; // output.
LIS_SPI_DIR &= ~BIT2; // input.
LIS_SPI_SEL |= (BIT3+BIT1+BIT2); // select alternate pin function.
LIS_SPI_OUT |= BIT4;
UCB1CTL1 = UCSWRST; // **Put state machine in reset**.
UCB1CTL0 = UCSYNC;
UCB1CTL0 |= UCMST;
UCB1CTL0 &= ~UCCKPL;
UCB1CTL0 |= UCCKPH;
UCB1CTL0 |= UCMSB;
UCB1CTL1 |= (UCSSEL1 + UCSSEL0); // MCLK.
UCB1BR0 = 0x02; // /2.
UCB1BR1 = 0; //.
UCB1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**.
}
void write_eeprom(void)
{
UC1IFG &= ~UCB1RXIFG; // !! verify if correct interrupt flag register is being used.
LIS_SPI_OUT &= 0xEF; // enable SPI interface
__delay_cycles(15); // wait to ensure tsu (min 6ns)
UCB1TXBUF = WREN;
__delay_cycles(15); // wait to ensure tsu (min 6ns)
LIS_SPI_OUT |= 0x10; // disable SPI, transfer complete
__delay_cycles(15); // wait to ensure tsu (min 6ns)
LIS_SPI_OUT &= 0xEF; // enable SPI interface
__delay_cycles(15); // wait to ensure tsu (min 6ns)
*/
UCB1TXBUF = WRITE;
UCB1TXBUF = 0x01;
UCB1TXBUF = 0x02;
UCB1TXBUF = 0x01;
UCB1TXBUF = 0xAA;
__delay_cycles(15); // wait to ensure tsu (min 6ns)
LIS_SPI_OUT |= 0x10; // disable SPI, transfer complete
}
void read_status(void)
{
LIS_SPI_OUT &= 0xEF; // enable SPI interface
__delay_cycles(15); // wait to ensure tsu (min 6ns)
UCB1TXBUF = RDSR;
while (!(UC1IFG & UCB1RXIFG)); // USCI_A1 TX buffer ready?
if (UCB1RXBUF == 0xAA) // Test for correct character RX'd
P1OUT |= 0x01;
_delay_cycles(15); // wait to ensure tsu (min 6ns)
LIS_SPI_OUT |= 0x10; // disable SPI, transfer complete
}
void read_eeprom(void)
{
LIS_SPI_OUT &= 0xEF; // enable SPI interface
__delay_cycles(15); // wait to ensure tsu (min 6ns)
UC1IFG &= ~UCB1RXIFG; // !! verify if correct interrupt flag register is being used.
UCB1TXBUF = READ;
UCB1TXBUF = 0x01;
UCB1TXBUF = 0x02;
UCB1TXBUF = 0x01;
while (!(UC1IFG & UCB1RXIFG)); // USCI_A1 TX buffer ready?
if (UCB1RXBUF == 0xAA) // Test for correct character RX'd
P1OUT |= 0x01;
_delay_cycles(15); // wait to ensure tsu (min 6ns)
LIS_SPI_OUT |= 0x10; // disable SPI, transfer complete
}
// Test for valid RX and TX character
#pragma vector=USCIAB1RX_VECTOR
__interrupt void USCIB1RX_ISR(void)
{
volatile unsigned int i;
while (!(IFG2 & UCA0TXIFG)); // USCI_A1 TX buffer ready?
if (UCA0RXBUF == 0xAA) // Test for correct character RX'd
P1OUT |= 0x01; // If correct, light LED
else
P1OUT &= ~0x01; // If incorrect, clear LED
// MST_Data++; // Increment master value
// SLV_Data++; // Increment expected slave value
// UCA1TXBUF = MST_Data; // Send next value (Tx and Rx)
for (i = 30; i; i--); // Add time between transmissions to make sure slave can keep up
}