[Country EMBED strategy] [158] [SPI bare Metal Drive design]

Source: Internet
Author: User

SPI Controller Workflow

The SPI Controller provides 2 SPI interfaces. Each SPI interface has two channels, the TX channel and the RX channel, respectively. The CPU writes the data to the FIFO, writes the data to the Spi_tx_data register, so that the contents of this register are automatically moved to the sending FIFO, and if the CPU is going to read the data from the receiving FIFO, it accesses the register spi_rx_data, The data that receives the FIFO is then automatically moved to the Spi_rx_data register.

OK6410 SPI Bare-Metal program analysis

SPI initialization

U8 Spi_init () {

SPI Reset

Ch_cfg0 |= BIT5; SPI Soft Reset

Set Pin

Rgpccon &= ~0xffff;

Rgpccon |= 0x2222;

Configuring the CFG Register

Ch_cfg0 = 0b0111;

Configure MODE_CFG0

Mode_cfg0 = (63<<11);

Setting the Clock

clk_cfg0 = 100;

CLK_CFG) |= 1<<8;

return 0;

}

SPI Read/write

U32 spix_readwritedata (u32 txdata) {

do{

temp = (spi_stas0>>6) & 0x7F; Get the number of FIFO data sent

}whlie (Temp > 63); Send FIFO full, wait

SPI_TXDATA0 = TxData; Send data

do{

temp = (spi_stas0>>13) & 0x7F; Get the number of received data

}whlie (temp = = 0); Receive FIFO is empty, waiting for

return spi_rxdata0;

}

[Country EMBED strategy] [158] [SPI bare Metal Drive design]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.