SPI in Slave mode

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
ShM_1238346
Level 1
Level 1

Hi all,

   

I am trying to configure SPI in  PSoC 5 as Slave.

   

Whenever I do get a byte of data from the Master, I need to immediately transmit the byte to the Master.

   

The response to Master will change based on the data received from the Master.

   

The following are the configuration of the SPI slave:

   
        
  • Enabled the Rx internal interrupt
  •     
  • CPHA = 0 and CPOL =0
  •     
  • 8 bit word
  •     
  • Tied a interrupt component to SPIS
  •    
   

I am not able to get the interrupts and on the MISO line I am not able to see the data what I intended to transmit (Used an oscilloscope to check the data on MISO).

   

Can anyone let me know, what is wrong?

   

I have attached the project.

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

For a bit rate of 12 Mbit/s your provided 2MHz clock will not work. Better to choose internal clock for the SPI slave.

   

You set the internal interrupt which will handle all receive, but will not allow you to handle reading data from component. See the interrupts section in the datasheet.

   

You fill your Tx buffer each time the interrupt handler is called which will burn lots of MIPS.

   

I would suggest you to Increase the SPIS Rx and Tx buffers to 30bytes and let the component handle all the transfers automatically.

   

You can use a callback macro for detecting the initial byte of 0x55 or 0xff and then filling the Tx buffer appropriately once. Look into datasheet for "SPIS_RX_ISR_ExitCallback" for the right callback macro name.

   

Do not forget to clear the Rx Buffer after a complete transaction.

   

 

   

Bob

0 Likes

Hi Bob,

   

I am new to PSoC.

   

Can you please let me know how callback macro is useful?

   

Based on the contents of first few bytes received, the data to Master would get changed.

   

How can this be done?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Callback macros are explained in Creator Help. They are not interrupts, but may be an extension to a component interrupt. An example:

   

I2C component has just a single interrupt that fires before any internal processing is done. But there are four (4) Calback macros defined that are called before and after the processing.

   

 

   

Bob

0 Likes