Hi Ian,

Welcome to the list.

To me it looks like your not initializing P3 to an output (P3DIR |= BIT0;).
I believe the default (after PUC) is input.  Because P3 in an input the
Flash sees High-Z at !CS and the flash's behavior is probably undefined.

Chris Takahashi

-----Original Message-----
From: Ian Bobbitt [mailto:ibobb...@cs.indiana.edu] 
Sent: Wednesday, August 18, 2004 10:18 AM
To: mspgcc-users@lists.sourceforge.net
Subject: [Mspgcc-users] USART1 SPI troubles

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;
} 




-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to