Hi tery54
i want to use the spoc spi core to interface to an adc requiring 24 bit transfers. however, the spi core only supports transfers upto 16 bit. is it possible to do two transfers in order to get the full 24 bits without de-asserting the the slave select line (some devices don't like it if you do)?
I'm using an ADC which outputs 64 bits per sample (4channels á 16bit) via SPI. Therefore I use the Altera SPI core. Configure the core to have 16 bit register and then use the alt_avalon_spi_command() function in your application. BUT before you use it, copy it to your project folder rewrite it to use read and write data width of 16 bit.
orginal:
int alt_avalon_spi_command(alt_u32 base, alt_u32 slave,
alt_u32 write_length,
const alt_u8* wdata,
alt_u32 read_length,
alt_u8* read_data,
alt_u32 flags)
rewritten:
int alt_avalon_spi_command(alt_u32 base, alt_u32 slave,
alt_u32 write_length,
const alt_u16* wdata,
alt_u32 read_length,
alt_u16* read_data,
alt_u32 flags)
Don't forget the adopt the variables in the function to be 16 bit width.
Then call function with:
write_length = 0
wdata = dummy pointer (if you only want to read from adc) read_length = 2 (2 times 16 bit) read_data = address of an array with 2 x 16 bit dimension
flags = 0 (1 would be merge bit, but this is not necessary here)
Be aware if you want to rewrite the function to read only, by deleting everthing that deals with writing. This won't work. Because the SPI is full duplex and only applies SCLK when it writes to MOSI (you can leave MOSI unconnected in the block diagram in Quartus II). The core reads and write data parallel, but since C is executed step by step, the spi command writes, reads, writes, reads etc. So write zero bytes and leave all code concerning write access, as it is, expect the data width.Depending on the output of the ADC and the configuration of the SPI core regarding transmission of MSB or LSB first, you have to manipulate the two array values to create one 24 bit value out of the two 16 bit values.
kloocki