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.

read / write MSP430F5529

I'm programming a microcontroller msp430f5529 to use the SPI interface to communicate with an RFID tag ( SL900A ) . The goal is to write / read certain memory areas within the tag . Does anyone know how to help me ? and d grazi advance

  • You have told us your goal, but not what the problem is.

  • can i post  to you my code to explain my problem because i have a problem when i write in the tag ?

  • Put the problem description and the relevant code in the question.
  • #include <msp430.h>
    #include "Scrittura1.h"

    const unsigned char WRITE1=0x00; //1°byte comando di scrittura
    unsigned char WRITE2=0x64;
    unsigned char DATO=0x49;

    int main(void)
    {

    volatile unsigned int i;
    //unsigned int data;

    dog_Disable();
    Pin_init();
    USCIA0_Init();
    UCA0IE |= UCTXIE;

    __bis_SR_register(LPM0_bits + GIE);

    }

    #pragma vector=USCI_A0_VECTOR
    __interrupt void USCI_A0_ISR(void)

    {
    volatile unsigned int i;

    for(i=50;i>0;i--); // Enable USCI_A0 TX interrupt
    P1OUT=00000001;

    switch(__even_in_range(UCA0IV,4))
    {
    case 0: break; // Vector 0 - no interrupt
    case 2: break; // Vector 2 - RXIFG
    case 4: // Vector 4 - TXIFG
    {
    for(i=50;i>0;i--);

    USCIA0_SendChar(WRITE1);
    USCIA0_SendChar(WRITE2);
    USCIA0_SendChar(DATO);

    WRITE2++;

    for(i=50;i>0;i--);
    P4OUT&=~BIT1; //sen=0
    P4OUT|=BIT1;

    break;}
    default: break;

    }

    P1OUT=00000000;
    for(i=5000;i>0;i--);
    }
    ===============>>>>>>This is the main code



    void USCIA0_Init(void)
    {
    UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
    P4OUT|=BIT1; //sen=1
    UCA0CTL1 |= UCSSEL_1; // ACLK (32KHz)
    UCA0BR0 = 0x00; // no clock scale factor
    UCA0BR1 = 0x00;
    UCA0MCTL = 0x00; // No modulation
    UCA0CTL0 |=UCMSB+UCMST+UCSYNC; // 8-bit,sync mode, SPI master mode, MSB first
    UCA0CTL1 &= ~UCSWRST; // **Initialize USCIA0 state machine**

    //UCA0IE |= UCTXIE; // Enable USCI_A0 TX interrupt

    //call __interrupt void USCI_A0_ISR(void)

    // __bis_SR_register(LPM0_bits + GIE); // CPU off, enable interrupts
    //enable low power mode spegnendo la cpu e abilita
    //Genaral Interrupt Enable(GIE)
    }

    void dog_Disable(void)
    {
    WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
    }

    void Pin_init(void)
    {
    P1DIR |= 0xFF; // Set P1.0 for LED
    P1SEL |=0x00;
    P2DIR |=0xFF;
    P2SEL |=0x00;
    P2SEL |= BIT7; // P2.7 option select
    P3DIR |=0xFF;
    P3SEL |=0X00;
    P3SEL |= BIT3+BIT4; // P3.3,4 option select
    P4DIR |= 0xFF;
    P4DIR |= 0xDF; //PIN 4.4,5 UART
    P4SEL |=BIT4+BIT5;
    P6DIR |= 0xFF;
    P6SEL |=0x00; //set all unused pin

    }


    void USCIA0_SendChar(unsigned char c)
    {
    UCA0TXBUF=c; // Riempie il buffer di trasmissione e trasmette
    while(!(UCA0IFG & UCTXIFG)); // USCI_A0 TX buffer ready?
    //Se UCA0IFG & UCTXIFG=0 rimane nel while in attesa (il buffer è pieno)
    //Se UCA0IFG & UCTXIFG!=0 esce dal while perchè ha svuotato il buffer

    //UCA0IFG &= ~UCTXIFG; //UCA0IFG &= ~UCTXIFG Riporta il registro UCA0IFG allo stato precedente
    }

    void USCIA0_Init(void)
    {
    UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
    P4OUT|=BIT1; //sen=1
    UCA0CTL1 |= UCSSEL_1; // ACLK (32KHz)
    UCA0BR0 = 0x00; // no clock scale factor
    UCA0BR1 = 0x00;
    UCA0MCTL = 0x00; // No modulation
    UCA0CTL0 |=UCMSB+UCMST+UCSYNC; // 8-bit,sync mode, SPI master mode, MSB first
    UCA0CTL1 &= ~UCSWRST; // **Initialize USCIA0 state machine**

    //UCA0IE |= UCTXIE; // Enable USCI_A0 TX interrupt

    //Richiama __interrupt void USCI_A0_ISR(void)

    // __bis_SR_register(LPM0_bits + GIE); // CPU off, enable interrupts
    //Abilita low power mode spegnendo la cpu e abilita
    //Genaral Interrupt Enable(GIE)
    }


    void dog_Disable(void)
    {
    WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
    }




    void Pin_init(void)
    {
    P1DIR |= 0xFF; // Set P1.0 for LED
    P1SEL |=0x00;
    P2DIR |=0xFF;
    P2SEL |=0x00;
    P2SEL |= BIT7; // P2.7 option select
    P3DIR |=0xFF;
    P3SEL |=0X00;
    P3SEL |= BIT3+BIT4; // P3.3,4 option select
    P4DIR |= 0xFF;
    P4DIR |= 0xDF; //PIN 4.4,5 UART
    P4SEL |=BIT4+BIT5;
    P6DIR |= 0xFF;
    P6SEL |=0x00; //set all unused pin

    }


    void USCIA0_SendChar(unsigned char c)
    {
    UCA0TXBUF=c; // Riempie il buffer di trasmissione e trasmette
    while(!(UCA0IFG & UCTXIFG)); // USCI_A0 TX buffer ready?
    //Se UCA0IFG & UCTXIFG=0 rimane nel while in attesa (il buffer è pieno)
    //Se UCA0IFG & UCTXIFG!=0 esce dal while perchè ha svuotato il buffer

    //UCA0IFG &= ~UCTXIFG; //UCA0IFG &= ~UCTXIFG Riporta il registro UCA0IFG allo stato precedente
    }

    =================>>>>>>this is the included code "Scrittura.h"

    My goal should be to write DATO in contiguous memory areas on the RFID tag (SL900A) starting from EEPROM address 0x64.
    For example:
    If i try to write DATO=0x49 in the EEPROM the result is something like that 49 00 49 00 49 00....
    but i want to find something like that 49 49 49 49 49 49

    can you find where the problem is?
  • my problem is that writing operation jumps one memory area
  • The SL900A datasheet says:

    The WRITE command allows the interrogator to write a word (16 bits)

    Apparently, you must send 16 bits, and the address is word-based.

  • i m not using EPC Gen2 commands . im interrogating the SL900A from SPI interface
  • What happens when you write different data values? Is every second byte skipped, or is the SPI address treated as a word address?

  • when i wrote the different data it skipped also
  • Did you get 11 00 33 00 55 00 or 11 00 22 00 33 00?
  • sorry, i dont understand your answer
  • When you try to write the bytes 11, 22, 33, 44, 55, 66, what is the result?

  • i can just write one data (8 bits) each time. If i want to send 11 22 33 44 i have to rebuild my project 4 times changing the variable DATO=0x11,DATO=0x22,DATO=0x33,DATO=0x44
    if i do this i will obtain something like that:
    11 00 11 00 11 00...
    22 00 22 00 22 00...
    etc...
  • You are incrementing WRITE2; you can change DATO, too.
  • ok i tryied to increment DATO too...now when my program starts i have WRITE2=0x64 and DATO=0x67.
    The results is :
    67 00 69 00 6b 00 6d 00
    it seems that when use WRITE2++ or DATO++ the program adds 2 instead of 1.
  • No, it appears that the datasheet is lying, and you have to write words also with SPI.
  • SPI is a bit stream protocol. How many bits a transfer contains is defined by the slave and the master needs to know this. In theory any number (like 21) bits can make up a transfer. However, the USCI 8for convenience) groups the data in groups of 8 bit. OT send 16 bit, simply send two bytes. The slave doesn't see a difference. It just sees 16 bits coming in.
    Most slave I've seen that want a number of bits that are not a multiple of 8, simply take the last x bits received before you de-assert the chip select. So you can simply pad some bits to the beginning of the first byte.
    Many slaves expect 16bit values and when you just send 8 bit, then the missing second half is taken as 0x00.

**Attention** This is a public forum