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.

Reset SPI communication (3-wire mode)

Other Parts Discussed in Thread: MSP430F2013, MSP430F47176

I have a question on SPI communication.

Most sample code from TI shows that before using SPI, the SPI master resets SPI slave device. And according

to what I tried, without reset, the SPI communication does not correctly work.

 

 

I have two device on my mind. Device A is based on MSP430F47176. The other (Device B) is based on MSP430F2013.

I would like to use Device A as master of controlling Device B and other modules (such as SD card, PC serial).

However, I would like to obtain analog data from Device B also. The Device B obtian analog data, and every 64

times averaged data need to be sent to Device A.

 

 

In this case, should I use Device B as SPI master? The problem for using Device B as SPI master is

the reset of SPI slave device (in this case Device A) before establishment of SPI communication

between Device A and Device B.  The Device A will control power off/on of Device B. So the Device B

should not reset Device A after power up.

 

Are there any way to establish communication without reset of Device A from Device B? The MSP430F2013

seems not have SPI STE (or Chip Select). So, I may need to work with 3-wire SPI.

 

 

  • Teh 3 wire/4 wire naming is misleading. It only means the hardware-level support of the SPI, not the required wires of the SPI communication itself. Usually, you'll always need 5 wires, including GND and a CS line.

    The problem with the plain SPI data transfer is that it is not synchronized. Of course, each bit is sent with a clock pulse, but there is nothing determining the byte borders, or the start or stop or abort of a communication. This is where you'll need teh CS line.

    Teh STE pin, however, is only partial support of a chip select. IT will, if pulled high, disable the slaves data output and stop the clocking of the shift registers, but it will not reset the shift registers and it cannot, ogf course, reset any high-level protocol.

    So if you're doing your own slave, you should connect the masters CS signal with not only STE but also with an interrupt-capable port pin (I'd like to see an STE transition causing an interrupt by itself!).

    So if CS is pulled low, you'll get an interrupt and can immediately start stuffing the TXBUF with data. You only have some microseconds, if at all. Then, if CS it set high, you should also immediately reset your SPI hardware, reconfigure it, and (if the type of data allows it) put the first byte into TXBUF already.

    I think this is what is meant by 'resetting the slave'. It is not necessary to do a complete device reset at all, only the communication must be reset. But performing a complete device reset is fo course the very simplest way to do this.
    Pulling the plug is surely the easiest way to reset your TV to the first channel. But 'some' people use the remote control instead.

    It's a good approach to define the protocol in a ways that leading FF bytes are 'busy' bytes or 'don't care' , so you have enough time to prepare the data when the call comes. Remember, on SPI, the master won't wait for your answer. If the call comes, be ready. Immediately. Within nanoseconds.

    While being an SPI master is the simplest thing on earth, being an SPI slave is a real slave job. If speed isn't an issue, I'd recommend going for an I2C master/slave instead.

  • Thank you for your detailed reply, Jens-Michael.

     

    Jens-Michael Gross said:

    So if you're doing your own slave, you should connect the masters CS signal with not only STE but also with an interrupt-capable port pin (I'd like to see an STE transition causing an interrupt by itself!).

    So if CS is pulled low, you'll get an interrupt and can immediately start stuffing the TXBUF with data. You only have some microseconds, if at all. Then, if CS it set high, you should also immediately reset your SPI hardware, reconfigure it, and (if the type of data allows it) put the first byte into TXBUF already.

    I think this is what is meant by 'resetting the slave'. It is not necessary to do a complete device reset at all, only the communication must be reset. But performing a complete device reset is fo course the very simplest way to do this.
    Pulling the plug is surely the easiest way to reset your TV to the first channel. But 'some' people use the remote control instead.

    Thank you for this information. So I need to care the interruptable Port pin for the above approach.

     

    Jens-Michael Gross said:

    It's a good approach to define the protocol in a ways that leading FF bytes are 'busy' bytes or 'don't care' , so you have enough time to prepare the data when the call comes. Remember, on SPI, the master won't wait for your answer. If the call comes, be ready. Immediately. Within nanoseconds.

    I will use FF as leading bytes for busy state.

     

    Jens-Michael Gross said:

    While being an SPI master is the simplest thing on earth, being an SPI slave is a real slave job. If speed isn't an issue, I'd recommend going for an I2C master/slave instead.

    Current work is based on SPI connection. In the future work, I may consider to use I2C.

     

    I appreciate your reply.

     

     

  • Hi,

    note that the SPI hardware is just a simple shift register. There is a problem when you have two MCUs and both start after power-up with a disabled SPI module. So for both MCUs the SPI module have to be initialized. Because of the different code and the different start-up times one of the MCUs is earlier ready to receive data. In case the master is not ready (usually its digital I/Os are defined as digital inputs => floating input) the slave may get clock edges an shifts in first bits in its shift register.... This would now case an offset when the real data bytes are transmitted.

    So it seems that the TI sample code resolves this issue by keeping the slave as long in reset state as the master initializes its I2C module. I would either use a handshake signal that ensures that the master is configured first before the slave activates its SPI module (or at least the slave should reset the SPI hardware as soon as the master is completely initialized) or in case both chips are on the same PCB I would consider delays during start-up that guarantee that master completes initialization of its SPI module before the slave initializes its SPI module....

  • Voyager34 said:
    the slave may get clock edges an shifts in first bits in its shift register


    This shouldn't happen if both are powered from the same power source and the port pins are initialized properly.
    Yet it is indeed possible to catch some noise. Putting an external pullup to the clock line to VCC will eliminate this.

    Voyager34 said:
    So it seems that the TI sample code resolves this issue by keeping the slave as long in reset state as the master initializes its I2C module

      It is surely not a good thing to reset the slave just because the master resets. Imagine the slave being an MSP with RTC. The reset signal wil reset teh content of the RTC registers. Baaaad thing.
    A typical cheap solution that will only work on the demo code but not in a real world application.

    For the 'initialisation' the chip select signal is the usual and obvious solution. The slave initializes the SPI hardware but keeps the SWRST bit set. As soon as the CS line goes low, SWRST is reset and the first (dummy?) byte is put into TXBUF as fast as possible.

    Having an interrupt on the STE pin and having the STE pin connected with the SWRST bit (if required/configured) would be a really nice thing and make life much easier.
    But since this is not the case, the slave protocol must define a sufficient (worst-case) delay between CS and the first clock pulse.
    Well, with the RESET solution, (assuming teh reset signal as a CS signal) this is a loooong time. :(

     

**Attention** This is a public forum