为了使程序跑快些,我的SPI只发数据不接收,针对SPI发送函数我做了些改动:
// 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;
// This is Polled transfer as per section 10.6.1
// BUG ALERT: what happens if we get interupted in this section, and someone else
// accesses a different peripheral?
// Clear TX and RX fifos
bcm2835_peri_set_bits(paddr, BCM2835_SPI0_CS_CLEAR, BCM2835_SPI0_CS_CLEAR);
// Set TA = 1
//bcm2835_peri_set_bits(paddr, BCM2835_SPI0_CS_TA, BCM2835_SPI0_CS_TA);
// Maybe wait for TXD
while (!(bcm2835_peri_read(paddr) & BCM2835_SPI0_CS_TXD));
//delayMicroseconds(1);
// Write to FIFO, no barrier
bcm2835_peri_write_nb(fifo, value);
// Wait for DONE to be set
while (!(bcm2835_peri_read_nb(paddr) & BCM2835_SPI0_CS_DONE));
//delayMicroseconds(1);
// Read any byte that was sent back by the slave while we sere sending to it
//uint32_t ret = bcm2835_peri_read_nb(fifo);
// Set TA = 0, and also set the barrier
//bcm2835_peri_set_bits(paddr, 0, BCM2835_SPI0_CS_TA);
return 0;//ret;
}
1 SPI的CS信号改为手动控制
2 SPI不读接收到的数据,发送完直接返回
|