Hello,

I am trying to interface a MSP430F169 to an Atmel AT45DB021B flash.  As a first 
attempt, I am trying to read the status register, which contains a 
part-specific bit string for size determination, as well as a busy indicator.  
I have the data lines on USART1, and /CS on P3.0.  I have tried the following 
code to read from the part and output the register on P1, but have been 
unsuccessful thus far. This is my first MSP430 project.  What am I doing wrong, 
and how can I fix it?

#include <msp430x16x.h>
#include <stdlib.h>
#include <signal.h>
#include <io.h>

#define nCS_LOW { P3OUT &= ~BIT0; }
#define nCS_HIGH { P3OUT |= BIT0; }

#define WRITE_BYTE(b) { while ((IFG1 & UTXIFG1) == 1); TXBUF1 = b; }

int main(void);
void setup(void);
unsigned char read_status_reg(void);

int main(void)
{
  setup();
  nCS_HIGH;
  while(1)
  {
    P1OUT = read_status_reg();
  }
}

unsigned char read_status_reg(void)
{
  unsigned char x;
  nCS_LOW;
  while((IFG1 & UTXIFG1));
  TXBUF1 = 0x57; // read status reg
  x = RXBUF1;
  nCS_HIGH;
  return x;
}

void setup(void)
{
  WDTCTL = WDTPW|WDTHOLD;  // disable watchdog

  P1DIR = 0xFF;
  P1OUT = 0xFF;
 
  ME2    = USPIE1;
  UTCTL1 = SSEL1|SSEL0|STC;
  UCTL1  = CHAR|SYNC|MM;
  UBR01  = 0x02;
  UBR11  = 0x00;
  UMCTL1 = 0x00;

  P5SEL |= BIT1|BIT2|BIT3; // SPI 5.1-5.3
  P3OUT |= BIT0;           // nCS output;
} 



Reply via email to