SPI Clock problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SPI Clock problem

2,249 Views
longliveboy
Contributor I

Hi everybody;

 

I'm using LL16 and try to sent data to a DAC via SPI.

The problem is LL16 generates SPI clock only for 8bits but my hardware(DAC) needs 24bit continuos clock for successful data transfer. Is there any way to generate 24 bits clock with LL16

 

Thanks, 

Labels (1)
0 Kudos
5 Replies

486 Views
peg
Senior Contributor IV

Hi longliveboy,

 

As the SPI data register is buffered, by keeping it fed, you can produce an infinitely long continous clock and data. Basically you can transfer into the buffer while the actual shift register is still shifting out. When the shifting is done the buffer will transfer into the shift register and you have continuous operation.

 

0 Kudos

486 Views
longliveboy
Contributor I

PEG;

 

At the datasheet writes that do not send second data before transmit buffer empty flag is set.

 

 

I wrote this codes:

 

void sendSPI(byte adres, byte data1, byte data2){
  while (!SPIS_SPTEF);// check to see if SPI TX ready
   SPIS;       // clear status flags
 
  SPID = adres;   // load data into SPI register
 
  while (!SPIS_SPTEF);// check to see if SPI TX ready
   SPIS;       // clear status flags
 
  SPID = data1;   // load data into SPI register
 
  while (!SPIS_SPTEF);// check to see if SPI TX ready
   SPIS;       // clear status flags

  SPID = data2;   // load data into SPI register
  
  while (!SPIS_SPRF); // wait for receive full flag
   SPID;       // dummy read to clear flags

 

If u have any codes to implement your suggest i'll try and feedback again

0 Kudos

486 Views
jag
Contributor IV

longliveboy wrote:

PEG;

 

At the datasheet writes that do not send second data before transmit buffer empty flag is set.

 

[CUT] 

 

If u have any codes to implement your suggest i'll try and feedback again


It's why it exists an interrupt connected to the trasmit buffer empty flag. I suggest to use it.
 
Bye Jack 
 

 

0 Kudos

486 Views
bigmac
Specialist III

Hello,

 

There is an additional requirement, that an overrun condition must not occur, or further byte transfers will fail.  Therefore the SPRF flag must be cleared three times, each prior to the completion of transfer of the next byte.  This would apply even if you have no interest in the return data.

 

Some untested code - 

 

while (!SPIS_SPTEF);

SPID = adres;

while (!SPIS_SPTEF);

SPID = data1;        // Second byte queued to buffer

while (!SPIS_SPRF);  // Wait for completion of first byte

(void)SPID;          // Clear flag to prevent overrun

while (!SPIS_SPTEF);

SPID = data1;        // Third byte queued to buffer

while (!SPIS_SPRF);  // Wait for completion of second byte

(void)SPID;          // Clear flag to prevent overrun

while (!SPIS_SPRF);  // Wait for completion of third byte

(void)SPID;          // Clear flag

 

Interrupts should be disabled prior to starting this process, otherwise it is possible for an overrun to occur while an unrelated interrupt is serviced, especially with a fast SPI clock. 

 

Regards,

Mac

 

0 Kudos

486 Views
CarlFST60L
Senior Contributor II

As its async can you just send three bytes one after the other?

0 Kudos