Monday 19 August 2013

Cleared by Reading

It's been a while since my last update, and while I wish I had more to show off, I've been busy with... life. Back in July I resigned from my previous job, took a two week scuba and free diving holiday in Bali, I've just completed my third week with my new employer.



So anyway, I've decided to start tinkering again, and this afternoon I encountered something I hadn't really dealt with before. This debugging problem is pretty obvious when looking back, but had me stumped for half an hour.

I was trying to setup the RS-232 interface on a new development board, and I had to change the code to utilise USART6 instead of USART3 which I'd used previously. A library I had previously written uses interrupts to automatically store received characters into a FIFO buffer. However when I first changed the code to use the new peripheral, the buffer system wasn't working.

I set a breakpoint at the start of the "Read data register not empty" interrupt service routine, but it was never reached. The USART6 registers appeared to be configured correctly, so what else could it be? A few minutes later I realised what the problem was - the NVIC was not configured properly for this interrupt - and so once I had fixed, compiled and re-flashed the micro, I debugged again and this time when it ran the break point was reached. However, when I stepped through the code after the break point, I noticed that the check to see that the interrupt trigger was as expected (i.e. triggered by the RXNE flag) was not succeeding.

But what else could have triggered the interrupt? The RXNE interrupt was the only one currently enabled. Something strange was going on.

Then a strange thought occurred to me. I had all the USART6 registers 'exposed' for viewing in the 'EmbSys Registers' viewer in Eclipse. This plug-in allows easy viewing of all the DSP's registers, and it automatically reads the requested registers and presents them to the user whenever the processor is halted. I remembered the datasheet saying that the RXNE flag is cleared by a read to the USART's data register, DR.

Bingo.

Removing the breakpoint and placing a new one within the IF statement fixed everything, as did removing the DR register from the EmbSys Registers viewer. This is the kind of problem that could have stumped me for quite a while, but luckily I must have been thinking logically.