EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Interfacing serial flash with MSP430F149 for data logging

Started by saravana_friend81 February 22, 2005
hi all,
I am a learner in MSP 430. I am working in GPS application project.I
want to write some data in External serial flash memory through
MSp430F149.I am using serial flash memory for data logging purpose
from ST microelectronics part no M25P20.That serial flash connected
in SPI mode control protocol thru MSP430F149.The serial flash data
input line is connected to SIMO pin of MSP.The serial flash data out
pin is connected to SOMI pin.How to write a data in to that serial
flash in a particular location of serial flash.


This is the hardware connection for the above appln.


MSP430F149
-----------------
/|\| xt2in|-
| |          | 8MHz  SERIAL FLASH M25P20
--|RST xt2OUT|    - -------------
  |          |
  |      P3.1|------>|CS         |
  |SIMO0/P3.1|------>|DATAIN     |
  |UCLK0/P3.3|------>|SCLK       |
  |SOMI /P3.2|<------|DATAOUT    |
I have written the code as follows


#include "msp430x14x.h"
int SIGN,COUNT;



void main(void)
{
unsigned I;
int STATUS,BUFFER[300]; //buffer for storage
int A=0;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 &= ~XT2OFF; // XT2on

do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (I = 0xFF; I > 0; I--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still
set?

BCSCTL2 |= SELM_2 + SELS; // MCLK = SMCLK = XT2 (safe)


for (I = 0xFFFF; I > 0; I--); // Delay


//INITIALIZATION

ME1 |= USPIE0;//module enable
UCTL0 |= CHAR + SYNC + MM+ SWRST;// P3.1,2,3 SPI option select

UTCTL0 |= CKPL+SSEL1+STC;// // Polarity, 3-wire
UBR00 = 0x41;//8MHz clock rate with 9600 baud rate
UBR10 = 0x03;
UMCTL0 = 0x00;
ME1 |= UTXE0 + URXE0;//tx&Rx interrupt enable
UCTL0 &= ~SWRST;

IE1 |= URXIE0;
P6SEL |= 0x38;
P6DIR |= 0x38;
P6OUT = 0x30;
//*********READ ELECTRONIC SIGNATUREcommand sequece is 1.send
command 0xAB and three cummy byte *****************/
P3SEL = 0x0F;
P3DIR = 0x0A;
for(I=0xFFFF;I>0x0;I--);

while(!(IFG1 & UTXIFG0));
TXBUF0 = 0xAB;
//DUMMY BYTES
while(!(IFG1 & UTXIFG0));

TXBUF0 = 0x00;
while(!(IFG1 & UTXIFG0));
TXBUF0 = 0x10;
while(!(IFG1 & UTXIFG0));
TXBUF0 = 0x10;

_BIS_SR(GIE);
for(;;)
{
if(COUNT==1)
break;

}
P6OUT = 0x30
asm("nop;");
}

#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
SIGN = RXBUF0;
if(SIGN==0x11||SIGN==0xB)//check for electronic signature 0X11
COUNT=1;
}

In the above program i made a mistake but i dont know what is the
mistake.I got a result as 0x00 or 0xffh.any body can help me how to
write a code to read electronic signature thru MSP430f149 . I am
waiting for ur valuable guidance.
Thanks &Regards
Saravana







Beginning Microcontrollers with the MSP430

Check the specification from ST website.
For any operation you have to enable CS line (low) and then disable it
for example if your CS line is connected to P30:
#define SFCS_LOW  P3OUT &= 0xfe     // CS is P30
#define SFCS_HIGH P3OUT |= 0x01

SFCS_LOW             // CS active
// you code here
SFCS_HIGH            // CS inactive
Hope this will help
Jan


--- In msp430@msp4..., "saravana_friend81" 
<saravana_friend81@y...> wrote:
> 
> hi all,
> I am a learner in MSP 430. I am working in GPS application project.I
> want to write some data in External serial flash memory through
> MSp430F149.I am using serial flash memory for data logging purpose
> from ST microelectronics part no M25P20.That serial flash connected
> in SPI mode control protocol thru MSP430F149.The serial flash data
> input line is connected to SIMO pin of MSP.The serial flash data out
> pin is connected to SOMI pin.How to write a data in to that serial
> flash in a particular location of serial flash.
> 
> 
> This is the hardware connection for the above appln.
> 
> 
> MSP430F149
> -----------------
> /|\| xt2in|-
> | |          | 8MHz  SERIAL FLASH M25P20
> --|RST xt2OUT|    - -------------
>   |          |
>   |      P3.1|------>|CS         |
>   |SIMO0/P3.1|------>|DATAIN     |
>   |UCLK0/P3.3|------>|SCLK       |
>   |SOMI /P3.2|<------|DATAOUT    |
> I have written the code as follows
> 
> 
> #include "msp430x14x.h"
> int SIGN,COUNT;
> 
> 
> 
> void main(void)
> {
> unsigned I;
> int STATUS,BUFFER[300]; //buffer for storage
> int A=0;
> WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> BCSCTL1 &= ~XT2OFF; // XT2on
> 
> do
> {
> IFG1 &= ~OFIFG; // Clear OSCFault flag
> for (I = 0xFF; I > 0; I--); // Time for flag to set
> }
> while ((IFG1 & OFIFG)); // OSCFault flag still
> set?
> 
> BCSCTL2 |= SELM_2 + SELS; // MCLK = SMCLK = XT2 (safe)
> 
> 
> for (I = 0xFFFF; I > 0; I--); // Delay
> 
> 
> //INITIALIZATION
> 
> ME1 |= USPIE0;//module enable
> UCTL0 |= CHAR + SYNC + MM+ SWRST;// P3.1,2,3 SPI option select
> 
> UTCTL0 |= CKPL+SSEL1+STC;// // Polarity, 3-wire
> UBR00 = 0x41;//8MHz clock rate with 9600 baud rate
> UBR10 = 0x03;
> UMCTL0 = 0x00;
> ME1 |= UTXE0 + URXE0;//tx&Rx interrupt enable
> UCTL0 &= ~SWRST;
> 
> IE1 |= URXIE0;
> P6SEL |= 0x38;
> P6DIR |= 0x38;
> P6OUT = 0x30;
> //*********READ ELECTRONIC SIGNATUREcommand sequece is 1.send
> command 0xAB and three cummy byte *****************/
> P3SEL = 0x0F;
> P3DIR = 0x0A;
> for(I=0xFFFF;I>0x0;I--);
> 
> while(!(IFG1 & UTXIFG0));
> TXBUF0 = 0xAB;
> //DUMMY BYTES
> while(!(IFG1 & UTXIFG0));
> 
> TXBUF0 = 0x00;
> while(!(IFG1 & UTXIFG0));
> TXBUF0 = 0x10;
> while(!(IFG1 & UTXIFG0));
> TXBUF0 = 0x10;
> 
> _BIS_SR(GIE);
> for(;;)
> {
> if(COUNT==1)
> break;
> 
> }
> P6OUT = 0x30
> asm("nop;");
> }
> 
> #pragma vector=UART0RX_VECTOR
> __interrupt void usart0_rx (void)
> {
> SIGN = RXBUF0;
> if(SIGN==0x11||SIGN==0xB)//check for electronic signature 0X11
> COUNT=1;
> }
> 
> In the above program i made a mistake but i dont know what is the
> mistake.I got a result as 0x00 or 0xffh.any body can help me how to
> write a code to read electronic signature thru MSP430f149 . I am
> waiting for ur valuable guidance.
> Thanks &Regards
> Saravana




hi jan 
already i do that in correct way.first i enabled chip enable and 
then i write a program to read electronics signature of flash.Then i 
have some problem in my code.can any body help me.
thanks&regards 
saravana 


--- In msp430@msp4..., "Jan Szymanski" <janek@b...> wrote:
> 
> Check the specification from ST website.
> For any operation you have to enable CS line (low) and then 
disable it
> for example if your CS line is connected to P30:
> #define SFCS_LOW  P3OUT &= 0xfe     // CS is P30
> #define SFCS_HIGH P3OUT |= 0x01
> 
> SFCS_LOW             // CS active
> // you code here
> SFCS_HIGH            // CS inactive
> Hope this will help
> Jan
> 
> 
> --- In msp430@msp4..., "saravana_friend81" 
> <saravana_friend81@y...> wrote:
> > 
> > hi all,
> > I am a learner in MSP 430. I am working in GPS application 
project.I
> > want to write some data in External serial
flash memory through
> > MSp430F149.I am using serial flash memory for data logging 
purpose
> > from ST microelectronics part no M25P20.That
serial flash 
connected
> > in SPI mode control protocol thru
MSP430F149.The serial flash 
data
> > input line is connected to SIMO pin of
MSP.The serial flash data 
out
> > pin is connected to SOMI pin.How to write a
data in to that 
serial
> > flash in a particular location of serial
flash.
> > 
> > 
> > This is the hardware connection for the above appln.
> > 
> > 
> > MSP430F149
> > -----------------
> > /|\| xt2in|-
> > | |          | 8MHz  SERIAL FLASH M25P20
> > --|RST xt2OUT|    - -------------
> >   |          |
> >   |      P3.1|------>|CS         |
> >   |SIMO0/P3.1|------>|DATAIN     |
> >   |UCLK0/P3.3|------>|SCLK       |
> >   |SOMI /P3.2|<------|DATAOUT    |
> > I have written the code as follows
> > 
> > 
> > #include "msp430x14x.h"
> > int SIGN,COUNT;
> > 
> > 
> > 
> > void main(void)
> > {
> > unsigned I;
> > int STATUS,BUFFER[300]; //buffer for storage
> > int A=0;
> > WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> > BCSCTL1 &= ~XT2OFF; // XT2on
> > 
> > do
> > {
> > IFG1 &= ~OFIFG; // Clear OSCFault flag
> > for (I = 0xFF; I > 0; I--); // Time for flag to set
> > }
> > while ((IFG1 & OFIFG)); // OSCFault flag still
> > set?
> > 
> > BCSCTL2 |= SELM_2 + SELS; // MCLK = SMCLK = XT2 (safe)
> > 
> > 
> > for (I = 0xFFFF; I > 0; I--); // Delay
> > 
> > 
> > //INITIALIZATION
> > 
> > ME1 |= USPIE0;//module enable
> > UCTL0 |= CHAR + SYNC + MM+ SWRST;// P3.1,2,3 SPI option select
> > 
> > UTCTL0 |= CKPL+SSEL1+STC;// // Polarity, 3-wire
> > UBR00 = 0x41;//8MHz clock rate with 9600 baud rate
> > UBR10 = 0x03;
> > UMCTL0 = 0x00;
> > ME1 |= UTXE0 + URXE0;//tx&Rx interrupt enable
> > UCTL0 &= ~SWRST;
> > 
> > IE1 |= URXIE0;
> > P6SEL |= 0x38;
> > P6DIR |= 0x38;
> > P6OUT = 0x30;
> > //*********READ ELECTRONIC SIGNATUREcommand sequece is 1.send
> > command 0xAB and three cummy byte *****************/
> > P3SEL = 0x0F;
> > P3DIR = 0x0A;
> > for(I=0xFFFF;I>0x0;I--);
> > 
> > while(!(IFG1 & UTXIFG0));
> > TXBUF0 = 0xAB;
> > //DUMMY BYTES
> > while(!(IFG1 & UTXIFG0));
> > 
> > TXBUF0 = 0x00;
> > while(!(IFG1 & UTXIFG0));
> > TXBUF0 = 0x10;
> > while(!(IFG1 & UTXIFG0));
> > TXBUF0 = 0x10;
> > 
> > _BIS_SR(GIE);
> > for(;;)
> > {
> > if(COUNT==1)
> > break;
> > 
> > }
> > P6OUT = 0x30
> > asm("nop;");
> > }
> > 
> > #pragma vector=UART0RX_VECTOR
> > __interrupt void usart0_rx (void)
> > {
> > SIGN = RXBUF0;
> > if(SIGN==0x11||SIGN==0xB)//check for electronic signature 0X11
> > COUNT=1;
> > }
> > 
> > In the above program i made a mistake but i dont know what is the
> > mistake.I got a result as 0x00 or 0xffh.any body can help me how 
to
> > write a code to read electronic signature
thru MSP430f149 . I am
> > waiting for ur valuable guidance.
> > Thanks &Regards
> > Saravana




hi,
please check with the CRO the levels and activity on all pins -
the easiest way to do it is to read ID in a loop.
the code which works for me is (ID function only
and remember you have different port lines):

/* USART0 used as master SPI */
/* 8MHz/2=4MHz */

/* enable USART module */
//ME1 |= 0x40; /* 01000000 - USPIE0=1 */
U0CTL|=0x01; /* set SWRST */
U0MCTL=0;
U0BR0=0x02;
U0BR1=0x00;
/* select SIMO0 for P31/SIMO0 */
/*        SOMI0 for P32/SOMI0 */
/*        UCLK0 for P33/UCLK0 */
P3SEL|=0x0e;  /* 0000 1110 */

/* USART Control Register */
U0CTL=0x17;   /* 00010111 */
              /* ||||||||_____ SWRST=1 */
              /* |||||||______ MM=1 Master mode */
              /* ||||||_______ SYNC=1, SPI mode */
              /* |||||________ Listen=0 */
              /* ||||_________ CHAR=1, 8bit */
              /* |||__________ unused */
              /* ||___________ unused */
              /* |____________ unused */
/* Transmit Control Register */
//WASU1TCTL=0xf2;  /* 11110010 */  
U0TCTL=0x32;  /* 00110010 */  
              /* ||||||||_____ TXEPT=0 */
              /* |||||||______ STC=1 3-pin SPI */
              /* ||||||_______ unused */
              /* |||||________ unused */
              /* ||||_________ SSEL1 SSEL0  clock for baud is 
SMCLK */
              /* ||___________ CKPL=0 inactive clock level low, data 
out on rising edge */
              /* |____________ CKPH=0 */
/* Receive Control Register */
U0RCTL=0x00;  /* 00000000 */
              /* ||||||||_____ RXERR=0 */
              /* |||||||______ RXWake=0 */
              /* ||||||_______ URXWIE=0 */
              /* |||||________ URXEIE=0 */
              /* ||||_________ BRK=0 */
              /* |||__________ OE=0 */
              /* ||___________ PE=0 */
              /* |____________ FE=0 */
/* enable USART module */
ME1 |= 0x40; /* 01000000 - USPIE0=1 */
U0CTL&=0xfe; /* clear SWRST */

/* RX interrupt is used */
IE1=0x40;     /* 01000000 */
              /* ||||||||_____ NU */
              /* |||||||______ NU */
              /* ||||||_______ NU */
              /* |||||________ NU */
              /* ||||_________ NU */
              /* |||__________ NU */
              /* ||___________ URXIE0 */
              /* |____________ UTXIE0 */



/* Instruction Set */
#define WREN 0x06   /* Write Enable */
#define WRDI 0x04   /* Write Disable */
#define RDSR 0x05   /* Read Status Register */
#define WRSR 0x01   /* Write Status Register */
#define READ 0x03   /* Read Data Bytes */
#define FAST_READ 0x0b /* Read Data Bytes at Higher Speed */
#define PP 0x02     /* Page Program */
#define SE 0xd8     /* Sector Erase */
#define BE 0xc7     /* Bulk Erase */
#define DP 0xb9     /* Deep Power Down */
#define RES 0xab     /* Release from Deep Power-down */
/*********************************************************/
/*  Name        : SF_readID_SPI                          */
/*  Parameters  : none                                   */
/*  Returns     : signature byte                         */
/*  Scope       :                                        */
/*  Function    : to identify Serial flash               */
/*********************************************************/
unsigned char SF_readID_SPI(void)
{
unsigned char c;
P2OUT &= 0x7f;  /* 0111 1111 P27 active low */
putchar_uart0(READ); /* instruction */
putchar_uart0(0xff);  /* 3 dummy bytes */
putchar_uart0(0xff);
putchar_uart0(0xff);
putchar_uart0(0xff);  /* generate clock to read ID */
c=getchar_uart0();
c=getchar_uart0();
c=getchar_uart0();
c=getchar_uart0();
c=getchar_uart0();
P2OUT |= 0x80;  /* 1000 0000 P27 inactive high */
return c;
}
/* End of SF_readID_SPI **********************************/
Hope it will help
Jan

--- In msp430@msp4..., "saravana_friend81" 
<saravana_friend81@y...> wrote:
> 
> hi jan 
> already i do that in correct way.first i enabled chip enable and 
> then i write a program to read electronics signature of flash.Then 
i 
> have some problem in my code.can any body help me.
> thanks&regards 
> saravana 
> 
> 
> --- In msp430@msp4..., "Jan Szymanski" <janek@b...> wrote:
> > 
> > Check the specification from ST website.
> > For any operation you have to enable CS line (low) and then 
> disable it
> > for example if your CS line is connected to P30:
> > #define SFCS_LOW  P3OUT &= 0xfe     // CS is P30
> > #define SFCS_HIGH P3OUT |= 0x01
> > 
> > SFCS_LOW             // CS active
> > // you code here
> > SFCS_HIGH            // CS inactive
> > Hope this will help
> > Jan
> > 
> > 
> > --- In msp430@msp4..., "saravana_friend81" 
> > <saravana_friend81@y...> wrote:
> > > 
> > > hi all,
> > > I am a learner in MSP 430. I am working in GPS application 
> project.I
> > > want to write some data in External serial flash memory through
> > > MSp430F149.I am using serial flash memory for data logging 
> purpose
> > > from ST microelectronics part no M25P20.That serial flash 
> connected
> > > in SPI mode control protocol thru MSP430F149.The serial flash 
> data
> > > input line is connected to SIMO pin of MSP.The serial flash 
data 
> out
> > > pin is connected to SOMI pin.How to write a data in to that 
> serial
> > > flash in a particular location of serial flash.
> > > 
> > > 
> > > This is the hardware connection for the above appln.
> > > 
> > > 
> > > MSP430F149
> > > -----------------
> > > /|\| xt2in|-
> > > | |          | 8MHz  SERIAL FLASH M25P20
> > > --|RST xt2OUT|    - -------------
> > >   |          |
> > >   |      P3.1|------>|CS         |
> > >   |SIMO0/P3.1|------>|DATAIN     |
> > >   |UCLK0/P3.3|------>|SCLK       |
> > >   |SOMI /P3.2|<------|DATAOUT    |
> > > I have written the code as follows
> > > 
> > > 
> > > #include "msp430x14x.h"
> > > int SIGN,COUNT;
> > > 
> > > 
> > > 
> > > void main(void)
> > > {
> > > unsigned I;
> > > int STATUS,BUFFER[300]; //buffer for storage
> > > int A=0;
> > > WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> > > BCSCTL1 &= ~XT2OFF; // XT2on
> > > 
> > > do
> > > {
> > > IFG1 &= ~OFIFG; // Clear OSCFault flag
> > > for (I = 0xFF; I > 0; I--); // Time for flag to set
> > > }
> > > while ((IFG1 & OFIFG)); // OSCFault flag still
> > > set?
> > > 
> > > BCSCTL2 |= SELM_2 + SELS; // MCLK = SMCLK = XT2 (safe)
> > > 
> > > 
> > > for (I = 0xFFFF; I > 0; I--); // Delay
> > > 
> > > 
> > > //INITIALIZATION
> > > 
> > > ME1 |= USPIE0;//module enable
> > > UCTL0 |= CHAR + SYNC + MM+ SWRST;// P3.1,2,3 SPI option select
> > > 
> > > UTCTL0 |= CKPL+SSEL1+STC;// // Polarity, 3-wire
> > > UBR00 = 0x41;//8MHz clock rate with 9600 baud rate
> > > UBR10 = 0x03;
> > > UMCTL0 = 0x00;
> > > ME1 |= UTXE0 + URXE0;//tx&Rx interrupt enable
> > > UCTL0 &= ~SWRST;
> > > 
> > > IE1 |= URXIE0;
> > > P6SEL |= 0x38;
> > > P6DIR |= 0x38;
> > > P6OUT = 0x30;
> > > //*********READ ELECTRONIC SIGNATUREcommand sequece is 1.send
> > > command 0xAB and three cummy byte *****************/
> > > P3SEL = 0x0F;
> > > P3DIR = 0x0A;
> > > for(I=0xFFFF;I>0x0;I--);
> > > 
> > > while(!(IFG1 & UTXIFG0));
> > > TXBUF0 = 0xAB;
> > > //DUMMY BYTES
> > > while(!(IFG1 & UTXIFG0));
> > > 
> > > TXBUF0 = 0x00;
> > > while(!(IFG1 & UTXIFG0));
> > > TXBUF0 = 0x10;
> > > while(!(IFG1 & UTXIFG0));
> > > TXBUF0 = 0x10;
> > > 
> > > _BIS_SR(GIE);
> > > for(;;)
> > > {
> > > if(COUNT==1)
> > > break;
> > > 
> > > }
> > > P6OUT = 0x30
> > > asm("nop;");
> > > }
> > > 
> > > #pragma vector=UART0RX_VECTOR
> > > __interrupt void usart0_rx (void)
> > > {
> > > SIGN = RXBUF0;
> > > if(SIGN==0x11||SIGN==0xB)//check for electronic signature 0X11
> > > COUNT=1;
> > > }
> > > 
> > > In the above program i made a mistake but i dont know what is 
the
> > > mistake.I got a result as 0x00 or
0xffh.any body can help me 
how 
> to
> > > write a code to read electronic signature thru MSP430f149 . I am
> > > waiting for ur valuable guidance.
> > > Thanks &Regards
> > > Saravana





Memfault Beyond the Launch