以下驱动是spi2的应用
static void mmc_spi_config(void)
{
spi_deinit();
gpio_init(gpioc, gpio_pin_2, gpio_mode_out_pp_high_fast);
gpio_init(gpioc, gpio_pin_4, gpio_mode_in_fl_no_it);
gpio_init(gpioe, gpio_pin_5, gpio_mode_out_pp_high_fast);
spi_init(spi_firstbit_msb, spi_baudrateprescaler_256, spi_mode_master
, spi_clockpolarity_high, spi_clockphase_2edge,
spi_datadirection_2lines_fullduplex, spi_nss_soft,0x00);
spi_cmd(enable);
}
static
uchar spi_readwrite_byte(unsigned char byte)
{
/* loop while dr register in not emplty */
while(spi_getflagstatus(spi_flag_txe) == reset);
/* send byte through the spi1 peripheral */
spi_senddata(byte);
/* wait to receive a byte */
while(spi_getflagstatus(spi_flag_rxne) == reset);
/* return the byte read from the spi bus */
return spi_receivedata();
}
『本文转载自网络,64体育的版权归原作者所有,如有侵权请联系删除』