MC56F8 SPI communication with MCP3464

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MC56F8 SPI communication with MCP3464

1,416 Views
GabrielChies
Contributor I

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

0 Kudos
Reply
3 Replies

1,369 Views
GabrielChies
Contributor I

@xiangjun_rong 
Hello!
Thanks for the reply ill invest some time into it. Do you mind helping me out a bit more? Roughfly how would this piece of code look like?

I have the peripheral configured as follows.

GabrielChies_0-1705941035960.png

 

To send data, i only have to use "setReg16(QSPI0_DXMIT, value);" and it works just fine, the slave select as well (works with as much bites as I want to send). On the other hand, to receive data, I am having some trouble, as the data received seems to not be read in the correct order. Any tips?

GabrielChies_1-1705941281258.png

Hope you may be abble to help, thanks.

 

0 Kudos
Reply

1,361 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Pls refer to the two main file.

Hope it cab help you

BR

XiangJun Rong

1,377 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I see that the spi of MC56F8257 functions as master, it communicates with the

MCP3464 ADC converter.

In order to get real time response, I suggest you write the SPI register instead of calling spi driver.

You can use either polling mode or interrupt mode. For example, you use interrupt mode, in the ISR, you can read the sample data from spi receiver reg and write the transmitter reg. If you write for example 40 bits with /CS remaining low, you can use GPIO and connect with /ss pin of MCP3664

 

Hope it can help you

BR

XiangJun Rong

0 Kudos
Reply