I have created a simple SPI project for the S7G2-SK consisting of 2 SPI devices on top of sf_spi.
The first device is on r_sci_spi channel 0 with sf_spi SS configured for P103. I am not able to see any activity at all on PMODA P100,1,2,3 (MOSI/MISO/CK/SS). I have checked the peripheral configuration SCI0 on the Pins tab and things seem to be set right.
The second device is on r_sci_spi channel 1 with sf_spi_ss configured for P511. But I have configured the peripheral SCI9 for Simple SPI operation which assigns the SPI signals to P202,3,4,5. I am not able to see any activity on these pins, but I am able to see the SS go on P511.
What could I be doing wrong? Am I configuring things properly?
I could upload a project if that helps.
Also, can you point me to something written on the DTC Driver for Transmission/Reception. Not sure how to use this or if I want/need it.
In reply to adboc:
I need help. I cannot make the SPI driver work on the PMODA of SK-S7G2 board. I get SSP_ERR_UNSUPPORTED. If you know the fix, please share with me. Thank you.
SSP 1.3.0 version
E2 Studio 188.8.131.52
Board: S7G2 SK
Here is the spi driver configuration setup. (ThreadX, Framework, SPI driver)
In reply to Mike:
In reply to Lui Luigi:
Thank you for your quick response! I checked it right away. The default value for the property "transfer size" is 4 in my setup. It cannot be changed because it is locked. How can I unlock it? Thanks.
I removed g_tranfer0 and g_transfer1. All the transfer size properties in the framework disappear. Now, I can get SSP_SUCCESS! But the i2c data is not coming in because the data did not change and device ID is not correct.
Debug shows SSP_SUCCESS, but the device ID (buf) is not 0xFA (the BMC150 part).
I am using PMODA. It is SPI0. Does it mean channel 0? I set my SPI driver channel to 0. Would your setup like this? Thank you.
Thank you for your response. I want SPI on PMODA.
I looked up the schematic for PMODA and pin information. PMODA turns out to be only a simple spi port. It is not a SCI port that can be configured as SPI or I2C.
Here is my current configuration. (Hope you can see the diagrams)
Dia 1: I have enabled the SPI port. The port configuration seems correct to me.
Dia 2: I use the correct SPI driver for r_rspi port (SPI0) and set up for channel 0.
Dia 3: I configure P1_03 for the chip select signal.
I will use a logic analyzer to see whether the MCU generates correct signal waveform on the port or not.
The scope waveform reveals the problem. All the SPI sequence is only 1 byte long. The r_spi driver deselects SSL after every 8 clocks. This seems to be the reason why I don't get any data read.
So, the spi port (PMODA pin P1_3/1/0/2) is enabled correctly. Commands are sent to the spi BC150 sensor. But, the chip select does not remain low for the data reading portion. Very interesting.
Maybe I try to use the sci port (PMODB pin P4_13/11/10/12) with the spi configuration.
1. SSL and SCK
2. SSL and MOSI
In reply to garyj:
You are right!!! Now SSL0 stays low with your suggestion. The only remaining problem is MISO. It stucks at '1'. All read data is 0xff. Would you know why?
Thank you so much. Hope I am getting closer.
I found the real problem. There is a pull up resistor on the sensor board, but the pull up is not the problem of the read failure. The problem is caused by the setting on spi clock polarity (CPOL) and clock phase (CPHA).
Below diagram is chip ID read. I have the correct data (0xFA) out. I realized that the command bit must change at the falling edge of the clock (not the rising edge).
It is easy to have wrong settings and I did it. There are four possible settings. But, only two settings will work to get the correct data out.
Setting 1: Clock low when idle / Data sampling on odd edge, data variation on even edge.
Setting 2: Clock high when idle / Data sampling on even edge, data variation on odd edge.
These two settings will ensure that the command bit changes at the falling clock edge and the data bit is sampled at the rising clock edge.
Now I am going to try to use PMODB (SCI_spi) instead to read the sensor's data. Hope it will go smoothly for me.
Thank you for your wonderful help.
I finally got simple spi protocol working on PMODA. Wow. I did not realize it until I read your reply.
I took a study of both PMODA and PMODB ports. There are many possible configurations for SPI or I2C.
P1_2 P1_1 P1_0 P1_3
SPI0: RSPCK MOSI MISO SSL0 (r_spi)
SCI0: SCK MOSI MISO SS (sci_spi)
IIC1: -- SDA SCL -- (r_iic)
SCI0: -- SDA SCL -- (sci_i2c)
P4_12 P4_11 P4_10 P4_13
I can see that I can use either SPI0 or SCI0 to configure the SPI port on PMODA and PMODB. I can use IIC1 or SCI0 to configure the I2C port on PMODA while I can use SCI0 only to configure the I2C port on PMODA.
Question 1: Now, can I use SCI0 for both PMODA and PMODB if I have 2 SPI devices? I can have two SPI drivers that connect to SCI channel 0. But, their chip select signals will be different. I think that it is yes.
Question 2: A similar question for I2C. I think that it is probably Yes. Because the device address for each device is unique. I can have two I2C drivers with two different slave device address, but I set to the same SCI channel 0.
Look forward to hear what you think. In the meantime, I try to configure for all the possible pin configuration for SPI and I2C. It will be fun.
Thank you so much. I learned a lot from your tip.
Hi Michael, Without pin reconfiguration at runtime, it will not be possible to use SCI0 on both PMODA and PMODB, since they use different set of pins (P1 and P4 ports). If you would like to use two SPI devices on both PMODs, I suggest using SCI0 and SPI0. Similarly for I2C, you should configure SCI0 and IIC1. Regards, adboc