Hi there,
I would like to ask if there is possibility to invert polarity of "ss" pin of SPI interfaces using "lib_spi" by XMOS.
I have an IC which communicates via SPI when ss pin is set high. I have read the documentation of "lib_spi" and it looks like it's only one configuration of ss pin.
Could anybody give me an advise what I am supposed to change in the library or do you think that i should solve this problem in hw?
Thank you all for help and sorry for my bad english
Regards
lib_spi inverted polarity of "ss" pin
-
- Member
- Posts: 13
- Joined: Thu Jul 30, 2015 12:10 pm
-
- XCore Legend
- Posts: 1913
- Joined: Thu Jun 10, 2010 11:43 am
Are you using the XMOS device to be the SPI Master or SPI Slave ?
Be sure to confirm that SPI SS polarity through the IC datasheet is required to be active high which is not very common. Usually SPI SS is active low. It should be possible to solve this issue in software only.
From a quick review of the lib_spi source code, the SS pin is assigned like the following example:
for(unsigned i=0;i<num_slaves;i++)
p_ss <: 1;
So search for p_ss keyword in the source code files and then invert the polarity to suit your project.
For the above disable of slaves, the code will change to:
for(unsigned i=0;i<num_slaves;i++)
p_ss <: 0;
since your IC is the inverted logic and here is another example, change:
p_ss[active_device] <: 1 @ time;
to
p_ss[active_device] <: 0 @ time;
You will have to continue to search through the library source code files with .xc suffix to search and replace each find of p_ss to the desired active high logic. Consider to use the simulator to view the waveforms to see if you have it correct or attach an external logic analyzer to view the results.
Be sure to confirm that SPI SS polarity through the IC datasheet is required to be active high which is not very common. Usually SPI SS is active low. It should be possible to solve this issue in software only.
From a quick review of the lib_spi source code, the SS pin is assigned like the following example:
for(unsigned i=0;i<num_slaves;i++)
p_ss <: 1;
So search for p_ss keyword in the source code files and then invert the polarity to suit your project.
For the above disable of slaves, the code will change to:
for(unsigned i=0;i<num_slaves;i++)
p_ss <: 0;
since your IC is the inverted logic and here is another example, change:
p_ss[active_device] <: 1 @ time;
to
p_ss[active_device] <: 0 @ time;
You will have to continue to search through the library source code files with .xc suffix to search and replace each find of p_ss to the desired active high logic. Consider to use the simulator to view the waveforms to see if you have it correct or attach an external logic analyzer to view the results.
-
- Member
- Posts: 13
- Joined: Thu Jul 30, 2015 12:10 pm
Thank you mon2 for the time that you spent to answer my question.
You're right, this inverted polarity of ss pin is pretty rare, but I am sure that this pin has to be set high to enable communication. I have alredy successfully communicated with this IC using STM32 microcontroller.
Your answer was very helpfull form me. I will do what you advised!
Regards
~Automatyk
You're right, this inverted polarity of ss pin is pretty rare, but I am sure that this pin has to be set high to enable communication. I have alredy successfully communicated with this IC using STM32 microcontroller.
Your answer was very helpfull form me. I will do what you advised!
Regards
~Automatyk