Hi Yong Li
It's just the opposite. I don't want to wait. I'm gonna explain you.
- The app has 2 buffers, 1 counter, and 1 byte for reading SPI status register:
unsigned char bufferIN[6] // RX
unsigned char bufferOUT[6] // TX > [ 0x20, 0xE8, 0x03, 0x00, 0x00, 0x81 ]
unisgned char counter_spi
unisgned char Status
- SPI = slave mode, Data buffer size = 8 bits (only uses SPI1_DL)
- And 1 interruption:
ISR (interrupciospi)
{
Status = SPI1_S;
bufferIN[counter_spi] = SPI1_DL;
/******HERE IS MY PROBLEM******/
SPI1_DL = bufferOUT[counter_spi];
if (counter_spi == 5)
counter_spi++;
else
counter_spi = 0;
}
Every interruption (each byte recieved) it calls interrupciospi. Read the SPI1_S, then copy the DL to bufferIN[counterspi] and put bufferOUT[counterspi] to DL. Here is when I have the problem:
- If I put the bufferOUT directly to SPI1_DL, the app works fine.
- But if I process what I've recieved at bufferIN, the app doesn't work. For example, if I put for (i=0;i<10;i++) (just a delay) at /******HERE IS MY PROBLEM******/ , automatically waits until next CLK for send the bufferOUT. For testing, I always send [ 0x20, 0xE8, 0x03, 0x00, 0x00, 0x81 ] , but if it works correctly, I want to process bufferIN[1] and:
- If bufferIN[1] = 0x33 send [ 0x20, 0xE8, 0x03, 0x00, 0x00, 0x81 ]
- If bufferIN[1] = 0x34 send [ 0x20, 0xC5, 0x12, 0x60, 0x13, 0x81 ]
Example (working correctly, but not processing what I recieved):
first transmission (ok.jpg left)
1. SPI1_DL (previously) = 0x00 > Interruption > RX = 0x92 > bufferIN[0] = 0x92 > bufferOUT[0] = 0x20
2. SPI1_DL (previously) = 0x20 > Interruption > RX = 0x33 > bufferIN[1] = 0x33 > bufferOUT[1] = 0xE8
3. SPI1_DL (previously) = 0xE8 > Interruption > RX = 0x00 > bufferIN[2] = 0x00 > bufferOUT[2] = 0x03
4. SPI1_DL (previously) = 0x03 > Interruption > RX = 0x00 > bufferIN[3] = 0x00 > bufferOUT[3] = 0x00
5. SPI1_DL (previously) = 0x00 > Interruption > RX = 0x00 > bufferIN[4] = 0x00 > bufferOUT[4] = 0x00
6. SPI1_DL (previously) = 0x00 > Interruption > RX = 0x00 > bufferIN[5] = 0x00 > bufferOUT[5] = 0x81
next transmission (ok.jpg right)
1. SPI1_DL (previously) = 0x81 > Interruption > RX = 0x92 > bufferIN[0] = 0x92 > bufferOUT[0] = 0x20
2. SPI1_DL (previously) = 0x20 > Interruption > RX = 0x33 > bufferIN[1] = 0x33 > bufferOUT[1] = 0xE8
3. SPI1_DL (previously) = 0xE8 > Interruption > RX = 0x00 > bufferIN[2] = 0x00 > bufferOUT[2] = 0x03
4. SPI1_DL (previously) = 0x03 > Interruption > RX = 0x92 > bufferIN[3] = 0x00 > bufferOUT[3] = 0x00
5. SPI1_DL (previously) = 0x00 > Interruption > RX = 0x33 > bufferIN[4] = 0x0 > bufferOUT[4] = 0x00
6. SPI1_DL (previously) = 0x00 > Interruption > RX = 0x00 > bufferIN[5] = 0x00 > bufferOUT[5] = 0x81
Example (not working correctly):
first transmission (left)
1. SPI1_DL (previously) = 0x00 > Interruption > RX = 0x92 > bufferIN[0] = 0x92 > TIME FOR PROCESS > bufferOUT[0] = 0x20
2. SPI1_DL (previously) = 0x00 > Interruption > RX = 0x33 > bufferIN[1] = 0x33 > TIME FOR PROCESS > bufferOUT[1] = 0xE8
3. SPI1_DL (previously) = 0x20 > Interruption > RX = 0x00 > bufferIN[2] = 0x00 > TIME FOR PROCESS > bufferOUT[2] = 0x03
4. SPI1_DL (previously) = 0xE8 > Interruption > RX = 0x00 > bufferIN[3] = 0x00 > TIME FOR PROCESS > bufferOUT[3] = 0x00
5. SPI1_DL (previously) = 0x03 > Interruption > RX = 0x00 > bufferIN[4] = 0x00 > TIME FOR PROCESS > bufferOUT[4] = 0x00
6. SPI1_DL (previously) = 0x00 > Interruption > RX = 0x00 > bufferIN[5] = 0x00 > TIME FOR PROCESS > bufferOUT[5] = 0x81
next transmission (right)
1. SPI1_DL (previously) = 0x00 > Interruption > RX = 0x92 > bufferIN[0] = 0x92 > TIME FOR PROCESS > bufferOUT[0] = 0x20
2. SPI1_DL (previously) = 0x81 > Interruption > RX = 0x33 > bufferIN[1] = 0x33 > TIME FOR PROCESS > bufferOUT[1] = 0xE8
3. SPI1_DL (previously) = 0x20 > Interruption > RX = 0x00 > bufferIN[2] = 0x00 > TIME FOR PROCESS > bufferOUT[2] = 0x03
4. SPI1_DL (previously) = 0xE8 > Interruption > RX = 0x00 > bufferIN[3] = 0x00 > TIME FOR PROCESS > bufferOUT[3] = 0x00
5. SPI1_DL (previously) = 0x03 > Interruption > RX = 0x00 > bufferIN[4] = 0x00 > TIME FOR PROCESS > bufferOUT[4] = 0x00
6. SPI1_DL (previously) = 0x00 > Interruption > RX = 0x00 > bufferIN[5] = 0x00 > TIME FOR PROCESS > bufferOUT[5] = 0x81
Hope I explained correctly ^^
Thanks for your answer