AnsweredAssumed Answered

Using GPIO as Chip Select pin for SPI

Question asked by Amit Kumar on Apr 30, 2014
Latest reply on May 8, 2014 by martynhunt

Hi

I was wondering how efficient is it to use GPIO as Slave Select pin ?. When I wrote a code in which I am using a default Chip select pin and side by side using GPIO pin just to test what the difference is on probing both the pins, I found the following waveforms. The yellow(channel 1) of the oscilloscope shows the inbuilt CS pin. the Blue(channel 2) of the oscilloscope shows the GPIO pin.

 

cs.JPG.jpg

 

Here I am sending 6 bytes data so CS pin is going low 6 times in the first case it is going down in fixed interval but in later case CS pin is going to logic 0  for 6 times but not at fixed intervals. Below is the simple code which is in my infinite loop

 

 

for(;;)

{

CS_ClrVal(csp);

SM1_SendChar((read|ACC_X_H)<<8 |dc);

CS_SetVal(csp);

 

CS_ClrVal(csp);

SM1_SendChar((read|ACC_X_L)<<8 |dc);

CS_SetVal(csp);

 

CS_ClrVal(csp);

SM1_SendChar((read|ACC_Y_H)<<8 |dc);

CS_SetVal(csp);

 

CS_ClrVal(csp);

SM1_SendChar((read|ACC_Y_L)<<8 |dc);

CS_SetVal(csp);

 

CS_ClrVal(csp);

SM1_SendChar((read|ACC_Z_H)<<8 |dc);

CS_SetVal(csp);

 

CS_ClrVal(csp);

SM1_SendChar((read|ACC_Z_L)<<8 |dc);

CS_SetVal(csp);

}


The above test I did in FRDMK20D50M board where the SPI_CS is PTD0 and the external CS is PTE0

Actually in 1 of my project I am using KL05 uc in that there is only 1 dedicated CS pin, so in that case for adding multiple slave device I need to use GPIO. SO please help me out in this.


Regards

Amit Kumar

Outcomes