Good day,
While configuring the Hardware SPI of the MC56F8257 Microcontroller, I did face some issues that I would like some clarification on.
Specifically, what I am doing is setting up the SPI to communicate with the MCP34XX, an AD converter that outputs data through SPI at configurable intervals.
The data length of this output is also variable; currently, I am working with 32 bits of data. The value outputted by the chip has to be read before a new conversion is made, so I have the chip interrupt request trigger an interrupt on my microcontroller. Inside the interrupt, I must send 40 bits (8 are the read instruction, the rest are dummy bits to get the AD reading of 32 bits). I have tried some different things to read this without success.
The first issue faced resides in the fact that the Hardware SPI can be configured to use either 8 or 16 bits at each transfer. To get around this, I've tried to send the chars (8 bits) consecutively using the method "SPI_SendChar()" and manually handling the Chip Select. I was not able to read it using this method, so I changed the method to "SPI_SendBlock()", which takes a pointer to an array containing the data you want to send. This time I could not synchronize the CS because the Hardware sends the data at a different time from when I call the method, so I've tried to use the automatic CS. Instead of generating a single pull-down for the entirety of the data transfer, it generates one for each byte of the data I am transferring.
Faced by this issue and upon several trial and errors, I have decided to implement it by bit banging and got it to work. The issue here is the speed of communication, which is way slower. Also, while bit-banging (as the code runs inside of an interrupt routine), the rest of the code gets frozen. For this particular application, it is imperative to have high-speed communication so I can increase the data rate.
How could I get around these issues? Does anyone have a working example of an SPI communication working in a similar environment?
I would aprreciate if anyone could help me get the Hardware SPI to work.
Here is the reference manual for the microcontroler:
https://www.nxp.com/docs/en/reference-manual/MC56F825XRM.pdf
And here is the datasheet of the AD converter:
https://br.mouser.com/datasheet/2/268/20006180C_MCP3461_2_4_Two_Four_Eight_Channel_LowNo-2297874.pdf