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.

ez430-RF2500 demo program modification with bit bang SPI

Other Parts Discussed in Thread: MSP430F2274, SIMPLICITI, CC2500

The more I learn about microcontrollers, the more I realize I don't know what the hell I'm doing. So in addition to researching and confusing myself to death, I decided to ask for help here.

To begin with, I'm using the eZ430-RF2500 development tool. My goal is to use a Cirrus CS5460A energy meter chip to measure power usage and communicate that info to the MSP430F2274 on my target board via SPI. From there, I want the same functionality as the demo temperature sensor network that came with the device. In other words, I want the end device to transmit 3 bytes of power data wirelessly to the access point once per second. I will then capture the UART backchannel data with a datalogger.

Problems:

The CS5460A utilizes an SPI interface, however, so does the CC2500 on the ez430. It doesn't appear possible to use both USCI_A and USCI_B as SPI at the same time. Therefore, I will need to bit-bang an SPI interface using general IO pins. I have found canned examples of this online, but I am stumped as to incorporating them into the demo sensor network code. Why does SimpliciTI change port pin settings, according to the comments in the demo program? Can I use any available pins or not? Why is the UCA clock the UCB STE and vice versa? That just doesn't seem very smart, so maybe I am missing something.

I thought I had more questions, and I'll probably be back later with a few more. But in the meantime, if somebody can help me write a software SPI that will work with the demo program included with the ez430-rf2500, I will be eternally grateful. I'm just inexperienced when it comes to coding (especially of the embedded variety) I guess.

Thanks,

Josh

  • Josh,

    There is no problem using USCI_a and USCI_b at the same time.. they are independent... depending on the device they MAY share interrupts, but you just have to interpret the flasg  to get the appropriate data..

    I suggest you getting the individual pieces working, the tryand handle the combined interrupts.

     

     

  • Per the eZ430-RF2500's User's Guide, P3.0 is both UCB0STE and UCA0CLK, as well P3.3 is UCB0CLK and UCA0STE. I don't see how the same pin can be both the clock and the chip select for two different devices simultaneously. I have successfully used the USCI_A UART concurrently with the USCI_B SPI, since UART only uses 2 wires. I don't know how to implement two independent 4-wire SPI interfaces, though.

  • unless you are using 4 wire mde the UCX0STE signals are not used.. 4 wire mode is only used when there are multile masters where  the msp would have to listen on this pin to see when it can use the bus (The UCXoSTE signal is an INPUT whe used, dont confuse this as an output for a chip enable).. SO in most cases there is no problem using both at the same time..

     

     

     

     

  • the normal SPI mode is 3 wire mode..MOSI ,MISO and CLK..  the chip select is a GPIO (its not counted as part of the interface) . the STE signals are not chip selects from the MSP430 master..

     

  • If I'm reading the schematic right (page 18, figure 10 of the linked user's guide), the chip select pin on the CC2500 on the ez430-rf2500 developement tool is connected to P3.0, which is UCB0STE. Unfortunately, it is also UCA0CLK, which makes it difficult to use USCI_A SPI without causing trouble with the CC2500. I'm just trying to find a way around that. Thanks.

  • I didn't look at the schematics (or sample code)  for the dev tool, but as long as there is a spare pin it shouldn't be that hard to do a "green wire" fix.. and move the enable to another pin..

     

     

  • Could you clarify what you mean by "green wire fix"? Anyway, it isn't the enable I'm worried about; as you say, I can just use a general IO pin for that. But if my clock pin is already in use by another device, that's a problem, since the CC2500 is hardwired to the MSP430. Can I output my clock signal on another pin while still using UCA0SIMO and UCA0SOMI?

    Anyway, this is where I get into murky water. I can kind of understand what is happening in TI's canned SPI examples. But I'm definitely not going to be able to program my own SPI interface, unless it is much easier than I imagine.

  • For an example, I cribbed the following code from the internet. It is similar to an example provided by TI. I'll use it so I can ask specific questions about a concrete example, but if anybody has a better solution, I'm all ears.

    To begin with, I would need an ISR to wake up the uC once per second, instead of an infinite for loop, correct? Or is the infinite loop there for some other reason? If I already have a Timer A ISR set to wake the CPU up once per second, could I just copy the innards of the for loop into my current main loop?

    Second, I need two data pins, not one. I'm not sure how this works, because with SPI you have to transmit and receive simultaneously, right? I guess I could just shift out the contents of another register while shifting in the incoming data? Would I just #define DI 0x10 as as data in on P2.4? Or 0x04 P2.2?

    Also, I need to receive and store 24 bits of data, not 8. Is this just a matter of changing the counter? What about the registers used? How would I transmit an 8-bit command and immediately receive and store 24 bits of data by modifying the scheme below?

    Thanks for your help. I'm sure my programming ignorance is showing, but I'm greatly appreciative of ignorance-fighting in all its manifestations.

     

    #define CS 0x01 // P2.0 - Chip Select
    #define CLK 0x02 // P2.1 - Clock
    #define DO 0x08 // P2.3 - Data Out
    void main (void)
    {
    unsigned char ADCData;
    unsigned char Counter;
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    P2OUT = CS; // /CS set, - P2.x reset
    P2DIR |= CLK + CS; // /CS and CLK outputs
    P1DIR |= 0x01; // Set P1.0 to output direction
    for (;;) // Infinite loop
    {
    P2OUT &= ~CS; // /CS reset, enable ADC
    for (Counter = 8; Counter > 0;)
    {
    ADCData = ADCData << 1;
    if ((P2IN & DO) == DO)
    {
    ADCData |= 0x01;
    }
    Counter --;
    P2OUT |= CLK; // Clock high
    P2OUT &= ~CLK; // Clock low
    }
    P2OUT |= CS; // /CS set, disable ADC
    if (ADCData < 0x7F)
    {
    P1OUT &= ~0x01; // Clear P1.0 LED off
    }
    else
    {
    P1OUT |= 0x01; // Set P1.0 LED on
    }
    }
    }

  • "green wire fix" -> old timer talk, for fixing a mistake on a ckt board..

    even though the cc2500 is wired to the msp, there should be a way to cut the trace and route it to another pin...

     

    This is something that I will investigate in the future since I plan on using the cc2500 in a future product but I am tied up in a big project now thats consuming all my time..

     

**Attention** This is a public forum