EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

problem with 4 pin SPI

Started by buscalle January 26, 2009
Using 430F2274 and try to use SPI 4 pin.
First i tried with the example code with 3 pin SPI and it works but
when i change to 4 pins the SPI goes totaly dead, i want to use the
UCA 0STE to chip_enable on my HDSP2911 display.
UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC + 4; Just adding 4 for
setting to STE active low.

Cant figure out why this doesnt work.

Code:
//******************************************************************************
// MSP430F22x4 Demo - USCI_A0, SPI Interface to HC164 Shift Register
//
// Description: This program demonstrates USCI_A0 in SPI mode,
interfaced to
// a 'HC164 shift register, transferring the value contained in Data.
// The value is incremented in the mainloop, effectively incrementing
// HC164 QA - QH.
// ACLK = n/a, MCLK = SMCLK = default DCO ~1.2MHz, BRCLK = SMCLK/2
//
// MSP430F22x4
// -----------------
// /|\| XIN|-
// | | | ^ HC164
// --|RST XOUT|- | -------------
// | | |-|/CLR,B | 8
// | UCA0SIMO/P3.4|--------->|A Qx|--\->
// | UCA0CLK/P3.0|--------->|CLK |
// | | | |
//
//
// A. Dannenberg
// Texas Instruments Inc.
// April 2006
// Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version:
3.41A
//******************************************************************************
#include "msp430x22x4.h"

unsigned char Data;
volatile unsigned int i;

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P3SEL |= 0x19; // P3.0,4 USCI_A0 option
select
UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC + 4; // UCMODE 4-pin,
8-bit SPI master
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 |= 0x08;
UCA0BR1 = 0;
UCA0MCTL = 0;
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
machine**

Data = 0x0FF; // Load inital data

while(1)
{
Data++; // Increment Data value
while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = Data; // Byte to SPI TXBUF
for(i = 0xEFFF; i > 0; i--); // Delay
}
}

Beginning Microcontrollers with the MSP430

STE is an INPUT to the SPI Master. It disables the master to control
the bus. You must use a general digital output pin to control the #CS
pin of your slave(s) by software.

Michael K.

--- In m..., "buscalle" wrote:
>
> Using 430F2274 and try to use SPI 4 pin.
> First i tried with the example code with 3 pin SPI and it works but
> when i change to 4 pins the SPI goes totaly dead, i want to use the
> UCA 0STE to chip_enable on my HDSP2911 display.
> UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC + 4; Just adding 4 for
> setting to STE active low.
>
> Cant figure out why this doesnt work.
>
> Code:
>
//******************************************************************************
> // MSP430F22x4 Demo - USCI_A0, SPI Interface to HC164 Shift Register
> //
> // Description: This program demonstrates USCI_A0 in SPI mode,
> interfaced to
> // a 'HC164 shift register, transferring the value contained in Data.
> // The value is incremented in the mainloop, effectively incrementing
> // HC164 QA - QH.
> // ACLK = n/a, MCLK = SMCLK = default DCO ~1.2MHz, BRCLK = SMCLK/2
> //
> // MSP430F22x4
> // -----------------
> // /|\| XIN|-
> // | | | ^ HC164
> // --|RST XOUT|- | -------------
> // | | |-|/CLR,B | 8
> // | UCA0SIMO/P3.4|--------->|A Qx|--\->
> // | UCA0CLK/P3.0|--------->|CLK |
> // | | | |
> //
> //
> // A. Dannenberg
> // Texas Instruments Inc.
> // April 2006
> // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version:
> 3.41A
>
//******************************************************************************
> #include "msp430x22x4.h"
>
> unsigned char Data;
> volatile unsigned int i;
>
> void main(void)
> {
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
> P3SEL |= 0x19; // P3.0,4 USCI_A0 option
> select
> UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC + 4; // UCMODE 4-pin,
> 8-bit SPI master
> UCA0CTL1 |= UCSSEL_2; // SMCLK
> UCA0BR0 |= 0x08;
> UCA0BR1 = 0;
> UCA0MCTL = 0;
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> machine**
>
> Data = 0x0FF; // Load inital data
>
> while(1)
> {
> Data++; // Increment Data value
> while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
> UCA0TXBUF = Data; // Byte to SPI TXBUF
> for(i = 0xEFFF; i > 0; i--); // Delay
> }
> }
>

Hello!

If you use UCA0 in SPI mode, you need
CLK, MOSI, therefore P3.0, P3.4. (you don't need MISO
as you don't read from the display).
Therefore, your P3SEL is not 0x19 but 0x11.
You can actually use the STE pin, but in this case, call
it P3.3 because it should not be selected as STE.
In this case, don't forget P3DIR = 0x08 to select P3.3
as an output for your chip select.

Pascal

--- In m..., "buscalle" wrote:
>
> Using 430F2274 and try to use SPI 4 pin.
> First i tried with the example code with 3 pin SPI and it works but
> when i change to 4 pins the SPI goes totaly dead, i want to use the
> UCA 0STE to chip_enable on my HDSP2911 display.
> UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC + 4; Just adding 4 for
> setting to STE active low.
>
> Cant figure out why this doesnt work.
>
> Code:
> //******************************************************************************
> // MSP430F22x4 Demo - USCI_A0, SPI Interface to HC164 Shift Register
> //
> // Description: This program demonstrates USCI_A0 in SPI mode,
> interfaced to
> // a 'HC164 shift register, transferring the value contained in Data.
> // The value is incremented in the mainloop, effectively incrementing
> // HC164 QA - QH.
> // ACLK = n/a, MCLK = SMCLK = default DCO ~1.2MHz, BRCLK = SMCLK/2
> //
> // MSP430F22x4
> // -----------------
> // /|\| XIN|-
> // | | | ^ HC164
> // --|RST XOUT|- | -------------
> // | | |-|/CLR,B | 8
> // | UCA0SIMO/P3.4|--------->|A Qx|--\->
> // | UCA0CLK/P3.0|--------->|CLK |
> // | | | |
> //
> //
> // A. Dannenberg
> // Texas Instruments Inc.
> // April 2006
> // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version:
> 3.41A
> //******************************************************************************
> #include "msp430x22x4.h"
>
> unsigned char Data;
> volatile unsigned int i;
>
> void main(void)
> {
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
> P3SEL |= 0x19; // P3.0,4 USCI_A0 option
> select
> UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC + 4; // UCMODE 4-pin,
> 8-bit SPI master
> UCA0CTL1 |= UCSSEL_2; // SMCLK
> UCA0BR0 |= 0x08;
> UCA0BR1 = 0;
> UCA0MCTL = 0;
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> machine**
>
> Data = 0x0FF; // Load inital data
>
> while(1)
> {
> Data++; // Increment Data value
> while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
> UCA0TXBUF = Data; // Byte to SPI TXBUF
> for(i = 0xEFFF; i > 0; i--); // Delay
> }
> }
>

So what you really mean is that i should toggle my chip select in
software. That would proporably work but i see it as a workaround. I
might change to a more advanced graphic lcd on later wersions so i
would most like it to work.

--- In m..., "p_murayama" wrote:
>
> Hello!
>
> If you use UCA0 in SPI mode, you need
> CLK, MOSI, therefore P3.0, P3.4. (you don't need MISO
> as you don't read from the display).
> Therefore, your P3SEL is not 0x19 but 0x11.
> You can actually use the STE pin, but in this case, call
> it P3.3 because it should not be selected as STE.
> In this case, don't forget P3DIR = 0x08 to select P3.3
> as an output for your chip select.
>
> Pascal
>
> --- In m..., "buscalle" wrote:
> >
> > Using 430F2274 and try to use SPI 4 pin.
> > First i tried with the example code with 3 pin SPI and it works but
> > when i change to 4 pins the SPI goes totaly dead, i want to use the
> > UCA 0STE to chip_enable on my HDSP2911 display.
> > UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC + 4; Just adding 4 for
> > setting to STE active low.
> >
> > Cant figure out why this doesnt work.
> >
> > Code:
> >
//******************************************************************************
> > // MSP430F22x4 Demo - USCI_A0, SPI Interface to HC164 Shift Register
> > //
> > // Description: This program demonstrates USCI_A0 in SPI mode,
> > interfaced to
> > // a 'HC164 shift register, transferring the value contained in
Data.
> > // The value is incremented in the mainloop, effectively
incrementing
> > // HC164 QA - QH.
> > // ACLK = n/a, MCLK = SMCLK = default DCO ~1.2MHz, BRCLK = SMCLK/2
> > //
> > // MSP430F22x4
> > // -----------------
> > // /|\| XIN|-
> > // | | | ^ HC164
> > // --|RST XOUT|- | -------------
> > // | | |-|/CLR,B | 8
> > // | UCA0SIMO/P3.4|--------->|A Qx|--\->
> > // | UCA0CLK/P3.0|--------->|CLK |
> > // | | | |
> > //
> > //
> > // A. Dannenberg
> > // Texas Instruments Inc.
> > // April 2006
> > // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version:
> > 3.41A
> >
//******************************************************************************
> > #include "msp430x22x4.h"
> >
> > unsigned char Data;
> > volatile unsigned int i;
> >
> > void main(void)
> > {
> > WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
> > P3SEL |= 0x19; // P3.0,4 USCI_A0 option
> > select
> > UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC + 4; // UCMODE 4-pin,
> > 8-bit SPI master
> > UCA0CTL1 |= UCSSEL_2; // SMCLK
> > UCA0BR0 |= 0x08;
> > UCA0BR1 = 0;
> > UCA0MCTL = 0;
> > UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> > machine**
> >
> > Data = 0x0FF; // Load inital data
> >
> > while(1)
> > {
> > Data++; // Increment Data value
> > while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer
ready?
> > UCA0TXBUF = Data; // Byte to SPI TXBUF
> > for(i = 0xEFFF; i > 0; i--); // Delay
> > }
> > }
>
OK i have simply missunderstood the STE function. It also explains why
i t goes totaly dead and actually works when i toggle STE externally.

Thanks for making this clear to me.

// Christian

The 2024 Embedded Online Conference