This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Communication between serial NOR Flash memory and msp430.

Other Parts Discussed in Thread: MSP430F5438A

I was trying to establish a communication between MSP430F5438A and SPI compatible serial NOR Flash memory. I could see the values in UCA0TXBUF register while writing to the NOR flash memory but did not receive any value in UCA0RXBUF register while reading it.

Is there any means by which i can know whether the values are getting written to the NOR Flash memory or not? If the NOR flash is working properly or not? Can i view the NOR Flash memory?

  • Hi Ananya,

    Do you mean that RXIFG never went high?  How long did you wait for it?  If you didn't wait for it, then you need to wait for the SPI exchange to finish.  If RXIFG never goes high, then the cause is a configuration error in the USCI.  As SPI master, you will always latch return data on MISO, whether somebody is driving that signal or not.

    Or do you mean that the value you read in RXBUF is not as expected?

    If you post some code that would help too.

    Jeff

  • UCA0IE goes high during transmission. So it means that the command to write in NOR Flash which i have to send first, then the data and then the command to read from the NOR Flash is being transmitted.

    But i am not able to know if the value is getting written in the NOR Flash or not?? because i am not receiving back data in UCA0RXBUF register.

    The NOR Flash i am working on is AT45DB321D. I will be glad if i could get some help to know if there is some error in the command or not?

    I am posting my code below:

    #include"msp430.h"
    void main(void)

    {
      WDTCTL = WDTPW + WDTHOLD;
      P5DIR = 0xFF;                                                             //to provide input to VCC pin
      P5OUT = 0xFF;
      P4SEL = 0xFF;                                                            //pull down the chip select pin
      P4OUT = 0x00;
      P3SEL = 0xFF;                                                            //TX and RX pins for SPI module
      P3OUT = 0xFF;
      char *p,*a,*b;
      p =(char*)0x1880;                                                       //location to store the value read from NOR Flash
      a =(char*)0x1900;                                                       //location to store the write command
      b =(char*)0x1980;                                                       //location to store the read command
      char c[]={1,0,0,0,0,0,1,1,0,0,0,0,0,0};                      //write command
      char d[]={1,1,1,0,1,0,0,0,0,0,0,0,0,0};                      //read command
      __disable_interrupt();
      FCTL3 = FWKEY;
      FCTL1 = FWKEY + ERASE;
      *p = 0;
      *a = 0;
      *b = 0;
      FCTL1 = FWKEY + WRT;
      for(int i=0;i<14;i++)
      {
          *a++ = c[i];                                                             
          *b++ = d[i];
      }
      a =(char*)0x1900;
      b =(char*)0x1980;
      UCA0CTL1 |= UCSWRST;                                                       //configuring the SPI module
      UCA0CTL0 |= UCMST+UCSYNC+UCMSB;   
      UCA0CTL1 |= UCSSEL_2;
      UCA0MCTL = 0;                             
      UCA0CTL1 &= ~UCSWRST;  
      UCA0IE |= UCRXIE;
     
       for(int j=0;j<14;j++)                                                                 //transmitting the write command to NOR Flash
       {
          UCA0TXBUF = *a++;
       }
     
       UCA0TXBUF = 0x11;                                                             //transmitting the value to be written
     
       for(int k=0;k<14;k++)
       {
          UCA0TXBUF = *b++;                                                         //transmitting the read command from NOR Flash
       }
     
      __bis_SR_register( GIE);                                                 
    }
    #pragma vector=USCI_A0_VECTOR
    __interrupt void USCI_A0_ISR(void)
    {
      char *p;
      p =(char*)0x1880;
      switch(__even_in_range(UCA0IV,4))
      {
        case 0: break;                         
        case 2:                               
           
          *p = UCA0RXBUF;                                                              //write the received data at location p
          p++;
          break;
        case 4: break;                          
        default: break;
      }
    }
            

                    
                                                
     

  • Ananya Pramanik said:
    for(int j=0;j<14;j++)                                                                 //transmitting the write command to NOR Flash
       {
          UCA0TXBUF = *a++;
       }

    This stuffs 14 bytes into TXBUF before the USCI has a chance to send even the first byte.
    There is no FIFO. TXBUF holds exactly one byte, then it's full. If you write to it before it's content has been move to the output shift register, you just overwrite the last value.

    Also, I don't think the write command is really "0x01, 0x00, 0x00...". I bet it is just a 16 bit value and the '1' and '0' you stored as string are really bits in this 16 bit value.
    So write command is 0010000011000000b = 0x20C0 and read is 0x3A00.

    Also, at the end of main you enable interrupts (btw: why do you use __bis_SR_register(GIE) to enable interrupts when you used __disable_interrupts() to disable them? It's effectively the same, but why using two different notations? It only causes confusion), but then you just fall out of main, which causes undefined behavior. There is no OS where you can return to, and even on a normal PC, this would exit the program and cancel all pending operations sucha s serial input.
    Go into a while(1) loop instead.
    In other demo programs, the PC often enters LowPowerMode on the last line (together with setting GIE), which also prevents main from exiting.

    One more thing: in your ISR, you define P as local variable. That means it gets created and initialized on every call of the ISR. I tmake sno sense to do p++ to get the data written serially to memory, when p is destroyed at the end of the ISR and initialized to the starting point on next ISR call.
    Make p a global volatile variable or at least a static local one (with a static iniitialization: "static char * p = (char*)0x1880")

**Attention** This is a public forum