Main Site Documentation

EMX - RLP - SPI Question



i ran in some problems using rlp on my cobra to send data over spi.
i collect all informations from the forum here and the example files from nxp.
using ghi’s rlp is not the problem. so here my code for spi init and spi writing :

void SPIInit()
  PCONP |= (1 << 8);	/* by default, it's enabled already, for safety reason */

  S0SPCR = 0x00;
  /* Port 0.15 SPI SCK, port0.16 uses GPIO SPI_SEL, 
  port0.17 MISO, port0.18 MOSI */
  //PINSEL0 |= 0xC0000000;
  PINSEL0 |= (0x02UL << 14) | (0x02UL << 18);

  SSP0CPSR = 254;  // SSP max speed
  /* Setting SPI0 clock, for Atmel SEEPROM, SPI clock should be no more 
  than 3Mhz on 4.5V~5.5V, no more than 2.1Mhz on 2.7V~5.5V */
  S0SPCCR = 0x8;


void WriteSPI(unsigned char* buf, unsigned int Length)
  unsigned int i;

  if ( Length == 0 )
  for ( i = 0; i < Length; i++ )
	S0SPDR = *buf;
	while ( !(S0SPSR & SPIF) );
  //Debug_println_STR("SPIWrite Ok)");

sending only some bytes is functional, sending a byte array of , for example, 384 bytes crashes the system. you can see the delay i insert, with this delay all run, without crashes. why ?? any hints ??
and what are the importent register settings in the spi init for only sending data bytes as fast as possible ?



Try this:

void WriteSPI(unsigned char* buf, unsigned int Length)
	while (Length--)
		while (!(SSP0SR & SSPSR_TNF));
		SSP0DR = *buf++;

Later edit:
I see you set 2 pins in SSP mode in PINSEL0. Those pins are from SSP1 and you use registers for SSP0. Also, you need at least 3 pins for bidirectional communication (MISO, MOSI, SCK).


Hey, thank you for the hints !
I’ve seen SSPSR_TNF in your code, but found this in no header file. From where do you get this ?

I only use SCK and MOSI, because i only send bytes, nothing to receive. Is this for this reason, ok ?
And what pins are for SSP0 ?
Many Questions, sorry :slight_smile:



SSPSR_TNF is a mask for TNF (transmit FIFO not full) bit from SSPxSR register. SSPSR_TNF = 0x02.
You don’t need any header file, just check the datasheet carefully.

SSP0 has the following pins:
SCK: P0.15
MISO: P0.17
MOSI: P0.18


I understand :slight_smile:

thank you !



You’re welcome.

You can see some part of the code I use to “talk” to VS1053 via SSP1 here: