Simple MCP52259 SPI routine

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

Simple MCP52259 SPI routine

Jump to solution
830 Views
MPotts
Contributor III

 

I want to implement some simple SPI routines to read and write sectors from/to a MicroSD card on an MCP52259 design. I have code to do this based on a low-level spi_byte() function. However I cannot find any simple MQX SPI examples as everything I look at seems to use more complex QSPI. This might create problems with the MicroSD card if it toggles CS on every byte (as I believe it does).

 

So far I have rebuilt the MQX kernel for the MCP52259 with (polled) SPI enabled. I am assuming that this will initialize SPI (channel 0) by default when MQX starts up so I don't have to. I also changed the chip select to CS2 as this is what we are using.

 

I am now faced wth a couple of choices. If I can disable QSPI CS byte toggling and separately control CS2 I could try to use the QSPI functions. Alternatively I could perform straight SPI8 functions and bypass QSPI (if I knew how).

 

Any advice/suggestions welcome.

 

Mark

0 Kudos
1 Solution
390 Views
MPotts
Contributor III

Thanks PetrM,

I will try this.

Mark

View solution in original post

0 Kudos
2 Replies
390 Views
PetrM
Senior Contributor I

Hello,

 

MQX QSPI driver is written in a way that holds CS asserted between bytes. This default behavior is the same for all xSPI module drivers.

So fwrite(buffer, 1, N, spi_fd) function writes N consecutive bytes with CS held down. To finally deassert CS, please call fflush (spi_fd).

 

Regards,

PetrM

 

0 Kudos
391 Views
MPotts
Contributor III

Thanks PetrM,

I will try this.

Mark

0 Kudos