资源简介
SPI.rar
代码片段和文件信息
#include “spi.h“
#include “stm8l15x_spi.h“
#include “led.h“
/*
note:
1 dma接收时数据会左移一位
2 正常接收时会出现丢包
*/
//硬件SPI驱动flash
uint8_t debug_status = 0;
uint32_t flash_id = 0;
uint8_t spi_tx_buf[DMA_BUF_TX_SIZE] = {0};
uint8_t spi_rx_buf[DMA_BUF_RX_SIZE] = {0};
uint8_t spi_busy_status = 0;
void spi_tx_dma_config(void);
//初始化
void spi_init(void)
{
CLK_PeripheralClockConfig(CLK_Peripheral_SPI1ENABLE);
SYSCFG_REMAPPinConfig(REMAP_Pin_SPI1FullENABLE);//开启PA2- PA3- PC6- PC5的重映射
//MISO
GPIO_Init(GPIOASPI_MISOGPIO_Mode_In_PU_No_IT);
GPIO_ExternalPullUpConfig(GPIOASPI_MISOENABLE);
//MOSI
GPIO_Init(GPIOASPI_MOSIGPIO_Mode_Out_PP_High_Fast);
GPIO_ExternalPullUpConfig(GPIOASPI_MOSIENABLE);
//CLK
GPIO_Init(GPIOCSPI_CLKGPIO_Mode_Out_PP_High_Fast);
//NSS
GPIO_Init(GPIOB SPI_NSS GPIO_Mode_Out_PP_High_Fast);
GPIO_SetBits(GPIOBSPI_NSS);
//SPI
SPI_DeInit(SPI1);
SPI_Init(SPI1 SPI_FirstBit_MSB SPI_BaudRatePrescaler_2 SPI_Mode_Master
SPI_CPOL_High SPI_CPHA_2Edge SPI_Direction_2Lines_FullDuplex SPI_NSS_Soft 0x07);
// SPI_ITConfig(SPI1SPI_IT_ERRENABLE);
// ITC_SetSoftwarePriority(SPI1_IRQn ITC_PriorityLevel_1);
SPI_Cmd(SPI1 ENABLE);
spi_tx_dma_config();
}
void spi_set_cs_high(void)
{
GPIO_SetBits(GPIOBSPI_NSS);
}
void spi_set_cs_low(void)
{
GPIO_ResetBits(GPIOBSPI_NSS);
}
uint8_t spi_send_onebyte(uint8_t data)
{
uint8_t recv;
/* Loop while DR register in not emplty */
while (SPI_GetFlagStatus(SPI1 SPI_FLAG_TXE) == RESET);
/* Send byte through the SPI1 peripheral */
SPI_SendData(SPI1 data);
/* Wait to receive a byte */
while (SPI_GetFlagStatus(SPI1 SPI_FLAG_RXNE) == RESET);
/* Return the byte read from the SPI bus */
recv = SPI_ReceiveData(SPI1);
return 0;
}
uint8_t spi_read_onebyte(void)
{
uint8_t data;
/* Loop while DR register in not emplty */
while (SPI_GetFlagStatus(SPI1 SPI_FLAG_TXE) == RESET);
/* Send byte through the SPI1 peripheral */
SPI_SendData(SPI1 0xFF);
/* Wait to receive a byte */
while (SPI_GetFlagStatus(SPI1 SPI_FLAG_RXNE) == RESET);
/* Return the byte read from the SPI bus */
data = SPI_ReceiveData(SPI1);
return data;
}
//写使能
void flash_chip_write_able(void)
{
//开始通讯
spi_set_cs_low();
//发送指令
spi_send_onebyte(FLASH_CHIP_WRITE_ENABLE);
//结束通信
spi_set_cs_high();
}
//写失能
void flash_chip_write_disable(void)
{
//开始通讯
spi_set_cs_low();
//发送指令
spi_send_onebyte(FLASH_CHIP_WRITE_DISABLE);
//结束通信
spi_set_cs_high();
}
uint8_t flash_chip_read_status(void)
{
uint8_t status;
//开始通讯
spi_set_cs_low();
//发送读状态指令
spi_s
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 11203 2018-05-10 10:29 spi.c
文件 1766 2018-05-10 10:29 spi.h
----------- --------- ---------- ----- ----
12969 2
- 上一篇:双目视觉特征点匹配三维重建
- 下一篇:数据库设计(学校教学管理系统
相关资源
- 王道2019数据结构视频链接.txt
- 总后台管理.xmind
- 坏蛋微信解封1.6.1.rar
- LC滤波器元件参数的计算.pdf
- license.key
- 淘淘商城.txt
- 互联网架构师VIP视频完整版.txt
- 马哥linux运维整套视频.txt
- zw_winsdk_web.zip
- network-disk-parse-master.zip
- springBoot全上下.txt
- vivado2016.4链接.txt
- 下载链接.txt51930
- 3559A.txt
- BankcardSelect.zip
- 基于51单片机仓库温度监控系统仿真设
- 基于51单片机简易信号发生器仿真设计
- 仿真.zip
- 抛丸机在用程序相互学习200smart.smar
- ideapycharm破解方法.zip
- SSC_1.0.rar
- React技术栈仿大众点评WebApp.txt
- dng.rar
- wxapp.7z
- avast激活码2018-2045.txt
- [赛门铁克.BackupExec].Backup_Exec_2012_14.
- EasySave-TheCompleteSaveLoadAsset.unitypackage
- 百度云链接.docx
- GBT29246-2012信息技术安全技术信息安全
- download.txt
评论
共有 条评论