This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello Team,
I need to establish SPI master/slave communication between two f28069f microcontrollers for motor control application.
The microcontroller boards have only following pins for SPI communication in both the boards:
SPI-B MOSI -> pin 97, GPIO24.
SPI-B SOMI -> pin 95, GPIO25.
SPI-B sclk -> pin 96, GPIO14.
SPISTEB pin is not configured for any of the predefined SPI module pins in the microcontroller, it is used for the other purpose in both the boards.
GPIO58 pin available, for configuring it has slave enable transmission pin(SPISTEB pin) in both the boards.
I want to know, whether I could use the GPIO58 pin has the SPISTEB pin in both the master and slave boards for slave enable transmission(SPISTEB). Since it doesn't belong to any of the predefined SPI module pins.
If it is possible, could please provide me the steps, or document to use the GPIO58 pin as the SPISTEB for both the Master/Slave configuration.
Requesting to please do the needful.
Thanks and best regards,
Chetan.
Hi Chetan,
Let me make it very simple: you can use slave select on any GPIO (SPISTE not required). Just that you need to keep playing with this GPIO to enable and disable when required and not respectively.
Regards,
Gautam
Chetan,
There are a few things to consider here.
1. The SPI master is able to manually control any GPIO to act as a Chip Select Signal. It must be controlled by the Software using standard GPIO Set/Clear. There are Various forum threads on this topic. Please use the Search to find them.
2. The SPI Slave is only able to use the GPIOs that have the SPISTEB signal muxed into it. There are a few options available to you if you cannot reallocate your GPIOs such that you have SPISTEB brought to a pin.
a. Do not bring out SPISTEB to any pin. If the Signal is not muxed to any pins, the default state is enabled. If the SPI Slave is always enabled, the SPI Slave will interpret any transition on SPICLK as a valid clock edge and act appropriately. We do not recommend this as the SPI Slave is susceptible to noise and could cause the Master/Slave link to become corrupted. You may be able to handle this resynchronization using software.
b. You may be able to implement Some sort of custom software synchronization using GPIO58. On the Slave side, you could hold the SPI in reset, preventing it from receiving any data. If the Master sends a trigger to the Slave, the Slave could exit reset and then handle any data input/output required. once the transmission is complete, the Slave would again enter reset to prevent any corruption.
I hope this gives you some ideas. If I misinterpreted your question, please let me know.
-Mark
Hello Gautham and Mark,
Thanks for your inputs.
I was able to establish SPI communication between both the boards, I have connected the SPITEB pin to ground, and keeping it low in the GPIO initialization.
But now the problem, data I receive in slave from the master is getting shifted.
An example of the data being transmitting from Master to Slave.
Master || Slave
0x1111 || 0x4444
0x2222 || 0x8888
0x0010 || 0x0040
0xF00F || 0xC03F.
In the above example, data is getting shifted by one bit.
At times, bits gets shifted by two or three bits place. Same happens when the data is transmitted from slave to master too.
I am writing the data in SPITXBUF register in the master, I am reading the received data from SPIRXBUF of the slave.
Settings in my Master and slave programs are as follows :
SysCtrlRegs.LOSPCP.all = 0x0006; / same clk for both master and slave.
SPI intialization for master as follows :
SpibRegs.SPICCR.bit.SPISWRESET=0; // Reset SPI
SpibRegs.SPICCR.all=0x000F; //16-bit character, Loopback mode
SpibRegs.SPICTL.all=0x0017; //Interrupt enabled, Master/Slave XMIT enabled
SpibRegs.SPISTS.all=0x0000;
SpibRegs.SPIBRR=0x007F; // Baud rate
SpibRegs.SPIFFTX.all=0xC022; // Enable FIFO's, set TX FIFO level to 4
SpibRegs.SPIFFRX.all=0x0022; // Set RX FIFO level to 4
SpibRegs.SPIFFCT.all=0x00;
SpibRegs.SPIPRI.all=0x0010;
SpibRegs.SPICCR.bit.SPISWRESET=1; // Enable SPI
SpibRegs.SPIFFTX.bit.TXFIFO=1;
SpibRegs.SPIFFRX.bit.RXFIFORESET=1;
SPI intialization for Slave as follows :
SpibRegs.SPICCR.bit.SPISWRESET=0; // Reset SPI
SpibRegs.SPICCR.all=0x000F; //16-bit character, Loopback mode
SpibRegs.SPICTL.all=0x0013; //Interrupt enabled, Master/Slave XMIT enabled
SpibRegs.SPISTS.all=0x0000;
SpibRegs.SPIBRR=0x007F; // Baud rate
SpibRegs.SPIFFTX.all=0xC022; // Enable FIFO's, set TX FIFO level to 4
SpibRegs.SPIFFRX.all=0x0022; // Set RX FIFO level to 4
SpibRegs.SPIFFCT.all=0x00;
SpibRegs.SPIPRI.all=0x0010;
SpibRegs.SPICCR.bit.SPISWRESET=1; // Enable SPI
SpibRegs.SPIFFTX.bit.TXFIFO=1;
SpibRegs.SPIFFRX.bit.RXFIFORESET=1;
Please let me know if anything has to be checked or changed.
Please find the attached screenshot.
In the above screen:
Yellow waveform : MOSI.
Green waveform : SYSCLK on the master side.
Pink waveform : SPISTE pin output, which is connected to ground.
Blue waveform : SYSCLK on the slave side.
Thanks in advance.
Best regards,
Chetan.
Chetan,
Does the data start out being shifted, or does the data become out of sync after some time?
If the data starts out shifted, It sounds like there is an extra clock edge early before your master begins it's transmission.
To be clear, the SPISTE on the Slave side is tied to ground? meaning that the pink signal is "SPISTE 'input'" instead of output? as I mentioned in my previous post. Tying the SPISTE to GND opens up your system to this sort of issue. Since the slave is always active, it will react to ANY transition on SPICLK, even noise. Please ensure that there are no unintentional transitions on SPICLK.
-Mark
Hello Mark,
Thanks for your inputs.
Since I couldn't find the details how to convert the GPIO58 to the custom slave enable, so I was following this procedure.
If I haven't understood instructions wrong, I would follow following procedure.
1. Master drive GPIO58 "active"
- Set GPIO58 as output and make it low.
2. Slave detect GPIO58 as active by polling, or by XINT
- Use external interrupt to make the slave pin active low.
3. Slave release SPI slave from reset.
- Slave SPI module is enabled.
4. Master start transmission.
- Data is sent from SPITXBUF.
5. Master end transmission.
- After the data is recieved by the slave(SPIRXBUF).
6. Master drive GPIO58 "inactive"
- Master should set SPISTE pin to high.
7. Slave detects GPIO58 as inactive
- Use XINT to detect the high and slave should be inactive.
8. Slave puts SPI into reset.
Please correct me if I am wrong at any of the step.
Best regards,
Chetan
Hello Mark,
I made the changes to the program as following.
1. GPIO58 pin was set has an output on the master side and it's initial value is kept high.
2. GPIO58 pin on the slave side is configured has input, and it's default value is high.
3. When the transfer interrupt ISR starts the GPIO58 pin on the master side is set low, which should cause the GPIO58 pin low on the slave side, since they are interconnected.
4. After the data is written to the SPITXBUF, GPIO58 pin is set high again on the master side.
With the above settings, I thought GPIO58 pin would be low until the data is transferred to the slave.
But GPIO58 would go low only for a short duration when the data is written to the SPITXBUF and it won't go low until data is received on the slave side.
Please find the screen for the same.
Yellow > SYSCLK.
Green > SPISTE.
Pink > MOSI.
I wanted to know is there any method which I can use to keep the GPIO58 pin low until data is received on the slave side.
I am not sure about how to XINT in this situation since I wasn't able to find any help online either.
I have also attached my master/slave code composer files.
Could you please help me with this.
Thanks in advance.
Best regards,
Chetan.
Hello Mark,
I made the changes to the program as following.
1. GPIO58 pin was set has an output on the master side and it's initial value is kept high.
2. GPIO58 pin on the slave side is configured has input, and its default value is kept high.
3. When the transfer interrupt ISR starts the GPIO58 pin on the master side is set low, which should cause the GPIO58 pin low on the slave side, since they are interconnected.
4. After the data is written to the SPITXBUF, GPIO58 pin is set high again on the master side.
With the above settings, I thought GPIO58 pin would be low until the data is transferred to the slave.
But GPIO58 would go low only for a short duration when the data is written to the SPITXBUF and it won't go low until data is received on the slave side.
Please find the screen for the same.
Yellow > SYSCLK.
Green > SPISTE.
Pink > MOSI
I wanted to know is there any method which I can use to keep the GPIO58 pin low until data is received on the slave side.
I am not sure about how to XINT in this situation since I wasn't able to find any help online either.
I have also attached my master/slave code composer files.
Could you please help me with this.
Thanks in advance.
Best regards,
Chetan.
Hello Mark,
I was able to get the waveforms for the GPIO58 has it was discussed earlier. But I am still getting error in my data received in the slave.
Please find the attached screen for the same.
Green : GPIO58(SPISTE)
Yellow : SYSCLK.
Pink : MOSI.
In the screen below, data sent is (0xABCD) from master on the falling edge of the sysclk.
Data sent matches the waveform of MOSI.
Please do let me know if anything has to be checked or changed.
Thanks and best regards,
Chetan
Chetan,
Can you try to provide a delay in between each transmission and see if that helps?
-Mark