MASTER & SLAVE Modes
My next task was to do something to make the PIC able to switch between the MASTER mode and the SLAVE mode. Generally, the MASTER mode will be the mode where the PIC will be acting as a server and will be receiving the bitstream from the Internet and then save the bitstream into the SD card, while the SLAVE mode will be the mode where the PIC will be reading the bitstream from the SD card and send the bitstream to program the FPGA and after that is done, the PIC will be switching into a state waiting command from the FPGA to perform one of the following function: ADC, Flash or Ethernet.
To achieve this, a bootloader is suggested to be used to allow both the MASTER and the SLAVE mode to use all the PIC’s RAM each for themselves instead of sharing the RAM with one another. But, it was soon realized that this might cause an issue with interrupt vectors of the PIC and a simpler way is advised to be used, which is to compile both the MASTER and SLAVE mode into one main function with two different loops. This comes with the expense of the both modes sharing the RAM and the flash. After some modification in the mainDemo.c, the combined code was able to fit into the PIC’s RAM and flash. A push button on the PICDEM.net 2 board is used to toggle the between the two modes.
To test the functionality of the changes on Port B interrupt, I would need an external device to change the value of RB4 to RB7. But, RB4 is used as the Card Detect pin for interacting with the SD card and there is only three modes on the slave PIC, thus RB5, RB6 and RB7 is chosen instead. The next is to use the Raspberry Pi to act as the MASTER to test the functionality of the interrupt to switch the PIC between different slave models. But, before that, the GPIO on the Raspberry Pi must be initialized and a multimeter is used to test the GPIO output.
After the GPIO is done, it is time to try to run a simulation of the slave PIC done by Kin Wai. But, the problem arises when the SPI on the Raspberry Pi is not found, the module is there but not the device. After a lot of troubleshooting, it is found that Umar has done some modification on the kernel of the Raspberry Pi. The Raspberry Pi is then wiped out to reinstall a new kernel (Raspbian) and all the data in it is lost but I backup the files created by Kin Wai in the Raspberry Pi on my computer.
After setting up the new kernel, the SPI is reinitialized and the SPI device is found. Connecting the Raspberry Pi to the programmed PIC and running one of the Python codes written by Kin Wai, the PIC is able to perform is slave function correctly. The next step is to include the GPIO output from the RPi to select the correct emulation mode of the slave PIC.