Forums

spi0 and uart0 may not be used simultaneously?

Started by williewortel July 29, 2011
Hi,

I had problems with communication through the SPI0 port.
Therefore I created a simple test, which sends 0x30 through
the uart0, just to say hello.
Then I read something from spi and dump it to uart0.
Then I write 0x31 through the uart to let know that the test ends.

The problem is that 2nd and 3th character is messed up when SPI read 0.
I simply left MISO0 floating or tied to VCC -> 0x30 0xFF 0x31.
I tied MISO0 to GND -> 0x30 0xrandom 0xrandom.

I tried the same with UART1 instead of UART0, which does seem to work.
Normally I use my own GNU toolchain, but to be sure that it isn't the
toolchain, I also tried with IAR and KEIL (modified an example).

I have one development board with an LPC2103 and one development board
with an LPC2141, tried with both boards (ofcourse changed the code to
make it suitable for the right uC). With the LPC2141 I first thought
it was the uC so I replaced the uC, but the problem persists.

short example of my code:
#include "lpc210x.h"
#include

unsigned char spird()
{

S0SPDR = 0xFFFF; // dummy
while(!(S0SPSR & 0x80));

return S0SPDR & 0xFF;
}

void spiwr(unsigned char data)
{

short c;

S0SPDR = data;
while(!(S0SPSR & 0x80));
c = S0SPDR;
}

int main(void)
{
unsigned char c;

APBDIV=0; /* APB set to 1/4 of CCLK */
PCONP=0x118;

PINSEL0=0x1505;
IO0DIR=0x80; // SSEL used as GPIO controlled CS

// init uart

U0LCR=0x83;
U0DLM=0;
U0DLL;
U0FDR=0x10;
U0LCR=0x03;
U0FCR=0;
U0IER=0;
U0ACR=0;
U0TER=0x80;

// init spi

S0SPCCR0; // SPIclk = 15MHz:30=0,5 MHz
S0SPCR=0x820;

// start test

U0THR=0x30;
while ((U0LSR & 32) == 0);

U0THR=spird();
while ((U0LSR & 32) == 0);

U0THR=0x31;
while ((U0LSR & 32) == 0);

while(1);

return 0;
}

An Engineer's Guide to the LPC2100 Series

Hi Willie, I had the same problem using SPI0 and UART1 with LPC2138...
 
Regardsm Boris.-

De: williewortel
Para: l...
Enviado: viernes, 29 de julio de 2011 12:03
Asunto: [lpc2000] spi0 and uart0 may not be used simultaneously?
 
Hi,

I had problems with communication through the SPI0 port.
Therefore I created a simple test, which sends 0x30 through
the uart0, just to say hello.
Then I read something from spi and dump it to uart0.
Then I write 0x31 through the uart to let know that the test ends.

The problem is that 2nd and 3th character is messed up when SPI read 0.
I simply left MISO0 floating or tied to VCC -> 0x30 0xFF 0x31.
I tied MISO0 to GND -> 0x30 0xrandom 0xrandom.

I tried the same with UART1 instead of UART0, which does seem to work.
Normally I use my own GNU toolchain, but to be sure that it isn't the
toolchain, I also tried with IAR and KEIL (modified an example).

I have one development board with an LPC2103 and one development board
with an LPC2141, tried with both boards (ofcourse changed the code to
make it suitable for the right uC). With the LPC2141 I first thought
it was the uC so I replaced the uC, but the problem persists.

short example of my code:

#include "lpc210x.h"
#include

unsigned char spird()
{

S0SPDR = 0xFFFF; // dummy
while(!(S0SPSR & 0x80));

return S0SPDR & 0xFF;
}

void spiwr(unsigned char data)
{

short c;

S0SPDR = data;
while(!(S0SPSR & 0x80));
c = S0SPDR;
}

int main(void)
{
unsigned char c;

APBDIV=0; /* APB set to 1/4 of CCLK */
PCONP=0x118;

PINSEL0=0x1505;
IO0DIR=0x80; // SSEL used as GPIO controlled CS

// init uart

U0LCR=0x83;
U0DLM=0;
U0DLL;
U0FDR=0x10;
U0LCR=0x03;
U0FCR=0;
U0IER=0;
U0ACR=0;
U0TER=0x80;

// init spi

S0SPCCR0; // SPIclk = 15MHz:30=0,5 MHz
S0SPCR=0x820;

// start test

U0THR=0x30;
while ((U0LSR & 32) == 0);

U0THR=spird();
while ((U0LSR & 32) == 0);

U0THR=0x31;
while ((U0LSR & 32) == 0);

while(1);

return 0;
}
At least I'm not the only one...
How did you solved the problem, or did you circumvent the problem?

Regards,

Willie

--- In l..., Boris Tormentor wrote:
>
> Hi Willie, I had the same problem using SPI0 and UART1 with LPC2138...
>  
> Regardsm Boris.-
>
> De: williewortel
> Para: l...
> Enviado: viernes, 29 de julio de 2011 12:03
> Asunto: [lpc2000] spi0 and uart0 may not be used simultaneously?
>
>
>  
> Hi,
>
> I had problems with communication through the SPI0 port.
> Therefore I created a simple test, which sends 0x30 through
> the uart0, just to say hello.
> Then I read something from spi and dump it to uart0.
> Then I write 0x31 through the uart to let know that the test ends.
>
> The problem is that 2nd and 3th character is messed up when SPI read 0.
> I simply left MISO0 floating or tied to VCC -> 0x30 0xFF 0x31.
> I tied MISO0 to GND -> 0x30 0xrandom 0xrandom.
>
> I tried the same with UART1 instead of UART0, which does seem to work.
> Normally I use my own GNU toolchain, but to be sure that it isn't the
> toolchain, I also tried with IAR and KEIL (modified an example).
>
> I have one development board with an LPC2103 and one development board
> with an LPC2141, tried with both boards (ofcourse changed the code to
> make it suitable for the right uC). With the LPC2141 I first thought
> it was the uC so I replaced the uC, but the problem persists.
>
> short example of my code:
>
> #include "lpc210x.h"
> #include
>
> unsigned char spird()
> {
>
> S0SPDR = 0xFFFF; // dummy
> while(!(S0SPSR & 0x80));
>
> return S0SPDR & 0xFF;
> }
>
> void spiwr(unsigned char data)
> {
>
> short c;
>
> S0SPDR = data;
> while(!(S0SPSR & 0x80));
> c = S0SPDR;
> }
>
> int main(void)
> {
> unsigned char c;
>
> APBDIV=0; /* APB set to 1/4 of CCLK */
> PCONP=0x118;
>
> PINSEL0=0x1505;
> IO0DIR=0x80; // SSEL used as GPIO controlled CS
>
> // init uart
>
> U0LCR=0x83;
> U0DLM=0;
> U0DLL=96;
> U0FDR=0x10;
> U0LCR=0x03;
> U0FCR=0;
> U0IER=0;
> U0ACR=0;
> U0TER=0x80;
>
> // init spi
>
> S0SPCCR=30; // SPIclk = 15MHz:30=0,5 MHz
> S0SPCR=0x820;
>
> // start test
>
> U0THR=0x30;
> while ((U0LSR & 32) == 0);
>
> U0THR=spird();
> while ((U0LSR & 32) == 0);
>
> U0THR=0x31;
> while ((U0LSR & 32) == 0);
>
> while(1);
>
> return 0;
> }
>

Well, in my case, the UART1 (interrupt driven) fail on receive bytes
after first use of SPI0 for transmit bytes (to SD/MMC card).
 
The UART1 can transmit bytes, but received bytes are
completely ignored. I tried to re-initialize UART1 hardware
and interrupts, but the error continues. 
 
I suspect a silicon-bug... (not confirmed).
 
Solution: Use UART0 instead of UART1 with SPI0 (in my project).
 
Regards,
Boris Estudiez.-
 
--
Slicetex Electronics
www.slicetex.com.ar
 
De: williewortel
Para: l...
Enviado: viernes, 29 de julio de 2011 16:43
Asunto: [lpc2000] Re: spi0 and uart0 may not be used simultaneously?
 
At least I'm not the only one...
How did you solved the problem, or did you circumvent the problem?

Regards,

Willie

--- In l..., Boris Tormentor wrote:
>
> Hi Willie, I had the same problem using SPI0 and UART1 with LPC2138...
>  
> Regardsm Boris.-
>
> De: williewortel
> Para: l...
> Enviado: viernes, 29 de julio de 2011 12:03
> Asunto: [lpc2000] spi0 and uart0 may not be used simultaneously?
>  
> Hi,
>
> I had problems with communication through the SPI0 port.
> Therefore I created a simple test, which sends 0x30 through
> the uart0, just to say hello.
> Then I read something from spi and dump it to uart0.
> Then I write 0x31 through the uart to let know that the test ends.
>
> The problem is that 2nd and 3th character is messed up when SPI read 0.
> I simply left MISO0 floating or tied to VCC -> 0x30 0xFF 0x31.
> I tied MISO0 to GND -> 0x30 0xrandom 0xrandom.
>
> I tried the same with UART1 instead of UART0, which does seem to work.
> Normally I use my own GNU toolchain, but to be sure that it isn't the
> toolchain, I also tried with IAR and KEIL (modified an example).
>
> I have one development board with an LPC2103 and one development board
> with an LPC2141, tried with both boards (ofcourse changed the code to
> make it suitable for the right uC). With the LPC2141 I first thought
> it was the uC so I replaced the uC, but the problem persists.
>
> short example of my code:
>
> #include "lpc210x.h"
> #include unsigned char spird()
> {
>
> S0SPDR = 0xFFFF; // dummy
> while(!(S0SPSR & 0x80));
>
> return S0SPDR & 0xFF;
> }
>
> void spiwr(unsigned char data)
> {
>
> short c;
>
> S0SPDR = data;
> while(!(S0SPSR & 0x80));
> c = S0SPDR;
> }
>
> int main(void)
> {
> unsigned char c;
>
> APBDIV=0; /* APB set to 1/4 of CCLK */
> PCONP=0x118;
>
> PINSEL0=0x1505;
> IO0DIR=0x80; // SSEL used as GPIO controlled CS
>
> // init uart
>
> U0LCR=0x83;
> U0DLM=0;
> U0DLL;
> U0FDR=0x10;
> U0LCR=0x03;
> U0FCR=0;
> U0IER=0;
> U0ACR=0;
> U0TER=0x80;
>
> // init spi
>
> S0SPCCR0; // SPIclk = 15MHz:30=0,5 MHz
> S0SPCR=0x820;
>
> // start test
>
> U0THR=0x30;
> while ((U0LSR & 32) == 0);
>
> U0THR=spird();
> while ((U0LSR & 32) == 0);
>
> U0THR=0x31;
> while ((U0LSR & 32) == 0);
>
> while(1);
>
> return 0;
> }
>