HELP! :smileysad:
If anyone has a clue or idea as to what my problem is, please fire away.
Thanks in advance.
Cheers,
Tom
Solved! Go to Solution.
lwevent_ works. So I'm over it, but I would still like to know what up with _lwsem_.
Cheers,
Tom
Hi Tom,
I was suffering a similar problem when using semaphores, and also I have found that using lwevent fixed it (also some timeouts and breakpoints put in "correct places"). I don't have the full explanation (mainly to the cases when it worked), but as you can read on last comments in Re: Posting semaphore from SPI IRQ crashes app it has to be taken into account that semaphores are used to synchronize tasks, while events can also be used to synchronize an ISR and a task.
Only as an idea: maybe were you in the same case as me, this is, a semaphore used to synchronize an ISR and a task and not several different tasks?
Regards,
José Antonio Martínez.
Has anyone seen this type of weirdness?
Cheers!
lwevent_ works. So I'm over it, but I would still like to know what up with _lwsem_.
Cheers,
Tom
Hi Tom,
I have K60F120M tower demo board. I use SPI1 as slave. I have tried both 16-bit word and 32-bit word data. I have no problem to use lwsem to notify main task. My problem is after first four words, the received data repeat the fourth data word. SPI has 4 word FIFO. I suspect the problem I have is related to FIFO set/clear.
Lisa
Hey Lisa,
you may be correct about the FIFO clear. In my 32-bit SPI ISR I clear the FIFO counter after I read in the 32 bits. so I'm back looking at the 1st FIFO, which should be the next to fill up.
SPI2_SR |= SPI_SR_RFDF_MASK | SPI_SR_RFOF_MASK ; //Clear SPI2 slave interrupt
SPI2_MCR |= (1UL << SPI_MCR_CLR_RXF_SHIFT); //Clear RXFIFO counter
So I get two interrupts to get 32 bits, filling up FIFO #1 & #2. Then I clear FIFO counter as above.
I hope this helps.
Cheers,
Tom
Hi Tom,
Thank you for help!
I have compared SPIx_SR and SPIx_MCR configuration in my spi1_isr(), I didn't clear SPI_SR_RFOF bit before. After reading your post, I have added it to spi1_isr(). Nothing has changed. This is the data received:
spi1_data = 0x6423
spi1_data = 0x849f
spi1_data = 0x1351
spi1_data = 0x1351
spi1_data = 0x1351
...
Note that since the third word received, its content never change. That is the problem I have. In this example, I use 16-bit word.
Below is my current isr function:
void spi1_rec_isr(void)
{
NVICICPR0 |= 1 <<27;
SPI1_SR |= SPI_SR_RFDF_MASK | SPI_SR_RFOF_MASK;
spi1_rx_data = SPI1_POPR;
SPI1_RSER = 0;
SPI1_MCR |= SPI_MCR_CLR_TXF_MASK | SPI_MCR_CLR_RXF_MASK | SPI_MCR_DIS_TXF_MASK | SPI_MCR_DIS_RXF_MASK;
_lwsem_post(&spi1_isr1_lwsem);
}
Could you see the problem? Do you mind show your isr function?
Thanks again.
Lisa
Hey Lisa,
What are you setting SPI1_RSER to signaling the interrupt? this is what I do:
SPI2_RSER = (1UL << SPI_RSER_RFDF_RE_SHIFT); // SPI2 interrupt when SPI2 RX FIFO is not empty
Maybe you are clearing too much with SPI1_MRC
Here is my isr stuff: Good luck :smileyhappy:
{ // Build 32-bits.
SpiMsW = (uint_16)(SPI2_POPR & 0xFFFF); // get SPI data MS_word.
SpiLsW = (uint_16)(SPI2_POPR & 0xFFFF); // get SPI data LS_word.
SPI2_MCR |= (1UL << SPI_MCR_CLR_RXF_SHIFT); // clear RXFIFO counter
SpiQlxWord = (((SpiMsW << 16) & 0xFFFF0000) | (SpiLsW & 0x00FFFF));
CardSpiState.rawSpiInWord = SpiQlxWord; // Save SPI word in private structure
_time_get_ticks(&ticks); // Get OS ticks
CardSpiState.timeIn = ticks.HW_TICKS; // Save ticks time stamp with SPI data
// post the lwevent to signal new SPI message is in
if (_lwevent_set(&lweventSPI,0x01) != MQX_OK)
_task_block(); // TODO: set a error condition instead if this.
SPI2_SR |= SPI_SR_RFDF_MASK | SPI_SR_RFOF_MASK ; //Clear SPI2 slave interrupt
SPI2_MCR |= (1UL << SPI_MCR_CLR_RXF_SHIFT); //Clear RXFIFO counter
}
Cheers,
Tom
Hi Tom,
Thank you for sharing your code!
I have noticed that you clear SPI2_MCR bit RXF twice. May I ask why?
I haven't got mine working yet.
Bye for now.
Lisa
I have noticed that you clear SPI2_MCR bit RXF twice. May I ask why?
Ha ha, I saw that also when I was sending the code. I am sure it is not needed to be done twice.
Hope you get it working.
Cheers,
Tom