User avatar
Posts: 215
Joined: Sat Sep 08, 2012 1:59 pm

SPI : transferring 16-bit into FIFO

Sat Nov 03, 2012 7:18 pm


Looking at the function
uint8_t bcm2835_spi_transfer ( uint8_t value)
( ... 09f47b7248),
then it writes 8 bit data byte to MOSI

Code: Select all

// Writes (and reads) a single byte to SPI
uint8_t bcm2835_spi_transfer(uint8_t value)
    volatile uint32_t* paddr = spi0 + BCM2835_SPI0_CS/4;
    volatile uint32_t* fifo = spi0 + BCM2835_SPI0_FIFO/4;
// Write to FIFO, no barrier
bcm2835_peri_write_nb(fifo, value);

Code: Select all

// write to peripheral without the write barrier
void bcm2835_peri_write_nb(volatile uint32_t* paddr, uint32_t value)
    if (debug)
	printf("bcm2835_peri_write_nb paddr %08X, value %08X\n",
               (unsigned) paddr, value);
	*paddr = value;
I am wondering how I can change the function into

Code: Select all

uint16_t bcm2835_spi_transfer(uint16_t value)
and then writing 16 bits data at once to the FIFO.

Any suggestions?

Thanks. Regards, Arjan
Open Source DMX/RDM/MIDI/OSC/Art-Net/sACN solutions

Posts: 325
Joined: Thu Sep 20, 2012 3:40 pm

Re: SPI : transferring 16-bit into FIFO

Sun Nov 04, 2012 6:25 pm

Hi Arjan!

You can only shift in 8 byte at a time.
So you have to split your 16 bit value in 2 assigns to the FIFO.
The only exception to this rule is DMA triggered transfer, where 32 bit get transferred at a time.

So you would have to do this for your 16 bit value:

Before writing you always should check if the fifo is filled to the max (by testing one of the bits in another register).


Posts: 1
Joined: Tue Mar 03, 2015 2:01 pm

Re: SPI : transferring 16-bit into FIFO

Tue Mar 03, 2015 2:07 pm


I have a question about some code lines like those above. Why are BCM2835_SPI0_FIFO or every other offsets, divided by 4 ?

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 19 guests