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.

SPI polling and programming in MSP430

Other Parts Discussed in Thread: MSP430F5309

Hi All,

I want to write an SPI master code. Using MSP430F5309, I have to transmit and receive data.

I checked the example codes of for MSP430F5309. None of them includes polling method. I want a code which polls the status bit in SPI register and trasmits data serially. 

If anybody has done that before, please share me the code.  I have a question by the way. Can the data be seen on the MISO/MOSI pins of SPI if the lines are un-connected. I am testing with an eval board and using CCS V5. In the debug mode, it has an option to load the program to the flash. My question is, if I program the flash and exit the debugger mode, will the program run or should I use debugging option to run the program. 

I just want to run my program on the eval board, just by programming it. Can I run it with the debugger connected or should I use external power supply.? 

Since I am new to MSP430 and TI, I am asking these dumb questions. 

Please help me regarding this.

  • Chaithra Bharadwaj said:

    I checked the example codes of for MSP430F5309. None of them includes polling method.

    Unless you have a Very Good Reason to use the polling method, it's best to follow what the TI example code does, which is using interrupts to handle the SPI communication. This allows you to put the MSP430 to sleep when it's not receiving or transmitting, so that it does not waste cycles and power. The sleep-interrupt method is the preferred programming model for the MSP430, see http://www.ti.com/litv/pdf/slaa294a

    On your second question, once you flashed the device you can either run the code within debug mode, or you can exit debug mode and hardware reset the device (using the RST button).

    And yes, the eval board is designed to be used with the debugger connected. However you can also provide your own power source if you wish. Just make sure the board and the debugger have shared ground in that case.

    Tony

  • Thanks Tony,

    Since I was using interrupts for other peripherals, I chose to use polling method for SPI. And yes, it worked with the eval board after programming . 

  • Chaithra Bharadwaj said:
    None of them includes polling method

    Polling is basically the same as unsing interrupts. The two differences are: the RXIE/TXIE bits mus tnot be set and the software needs to check/wait for TXIFG or RXIFG bits being set before writing to TXBUF or reading from RXBUF.

    Keep in mind that

    • for receiving a byte you have to send a byte
    • TXIFG is set when TXBUF is empty, and not when the last byte written to TXBUF has been sent. When TXIFG gets set, the former content of TXBUF has just moved to the output shift register and hasn't been sent yet.
    • a byte receive is complete when a byte write is complete. So in conjunction with the TXBUF double-buffering, this means you'll get the first byte shortly before TXBUF is ready for the third byte.

**Attention** This is a public forum