IR Control with self made FPGA and C program

Hi all,

I’ve made project that enables the commands of an IR remote (NEC protocol) to be stored, and also enables transmitting of any stored command to then program the device the remote is linked to.

I mainly done this to practice my VHDL coding and IR protocol understanding so I have created all the FPGA code and the C program that runs on the Raspberry Pi to read, store and write the IR data from scratch.

More detailed information and all the project file are uploaded to a Git repo at
I’m planning to do a full write up and add it to my website, but I have an odd issue.

It all works fine, except not the first time it’s programmed. At the moment when I load the FPGA bit file, then run the irCtl learn which trigger SPI comms and read the data, the data being read is wrong. I can confirm this by reading the IR RX line and SPI line with a logic analyser. While the IR RX line is as expected, the SPI data being transmitted from the FPGA to the RPi is a bit off (MISO line as RPi is master) such that a byte that should be 0x01 is now 0x02.

However, when then reloading the the FPGA .bit file (and every load thereafter), everything works as expected?!?!

To add, this does not happen on another FPGA board I have and it also needs to to have the SPI bus triggered, i.e. just reloading the .bit file again doesn’t fix the issue. Hence it would seem the issue could be with the SPI bus?

Anyway, hope a few can enjoy having a play if not help with issue!