Other Parts Discussed in Thread: HALCOGEN
Hello All,
I'm trying to write an SPI driver that the is using a MiBSPI via both polling and transfer groups.
The transfer group / MiB part is working well, the polling on the other hand, is causing me problems!
The datasheet, SPNU514B April 2015 - Table 27-24. SPI Receive Buffer Register (SPIBUF) Field Descriptions says:
Transmit data buffer full.This flag is a read-only flag. Writing into the SPIDAT0 or SPIDAT1 field while the TX shift register is full will automatically set the TXFULL flag. Once the word is copied to the shift register, the TXFULL flag will be cleared. Writing to SPIDAT0 or SPIDAT1 when both TXBUF and the TX shift register are empty does not set the TXFULL flag.
My understanding is that this flag is completley managed by the controller and each time that it is '0' I can write data into SPIDAT1. My problem is that this flag is never being set and the polling algorithm always thinks that the TXBUF is free. As a result, a tranfer of 7 SPI frames results in only frames 1, 4 & 7 appearing on a logic analyser. I have logged the all of the SPIBUF reads that occur during the polling, of which there are around 64 before a software timeout, and at no point does the TXFULL flag get set. The RXEMPTY flag does behave based on my understanding of the datasheet. I put a debug GIO pulse around the write to the SPIDAT1 and I can see that the polling is writing three times to the SPIDAT1 register before the first 2 MHz 8-bit frame completes its transfer. This seems to contradict the data sheet as the TX Shift Register and the TXBUF should both be full after the second write.
I have looked in the HalCoGen code for insperation and it uses bit 8 of the SPIFLG register (RXINTFLG) to determine that the transfer is complete. This is not a very efficient implementation as it causes gaps between the transmitted frames. The TXFULL flag mechanism ensures that the TX Shift Register is loaded immediatley after the completion of a frame as the TXBUF is kept full.
I have checked the ERRATA and cannot find anything relevant.
Can someone please correct my misunderstanding of this mechanism?