当前位置:网站首页>[Development Tutorial 4] open source Bluetooth heart rate waterproof sports Bracelet - external flash reading and writing
[Development Tutorial 4] open source Bluetooth heart rate waterproof sports Bracelet - external flash reading and writing
2022-07-24 21:13:00 【efans_ Mike】
Open source Bluetooth heart rate waterproof SPORTS BRACELET
—— Crazy shell · Intelligent wearable development series
external Flash Reading and writing
1 SPI+ brief introduction
In this section , We will use DA14580 Self contained SPI+ To conduct external Flash Read and write operations .
SPI(Serial Peripheral interface), Serial peripheral interface , Yes Motorola First of all MC68HCXX Defined on the family processor .SPI The interface is mainly used in EEPROM、FLASH、 Real time clock 、AD converter , And between the DSP and the DSP .
This interface is generally used 4 line : Serial clock line (SCLK)、 Host input / Slave output data line MISO、 Host output / Slave input data line MOSI And low level effective slave selection line NSS.
We DA14580 This SPI+ Interface support SPI A subset of the bus . This serial interface is in the main / The slave mode can send and receive 8、16 or 32 position , And in main mode, you can send 9 position .SPI+ Interfaces are bidirectional 2*16 A word FIFO, Enhanced functionality .
Our interface can work in master or slave mode ; Yes 8、9、16、32 Bit operation mode ;SPI The clock of the controller reaches 16MHz,SPI The clock source can be programmed 1、2、4、8 frequency division ;SPI The clock line reaches 8MHz; Support SPI Of 0、1、2、3 Four working modes ;SPI——DO The idle level of can be set by programming ; Maskable interrupt generator ; One way read and write mode reduces bus load .
2 Hardware design
The external we used this time Flash yes W25X20CL, It has 8 One pin .1 Pin No CS For chip selection .2 Pin No DO It's the data output pin .3 Pin No WP It's write protected .4 Number is GND.5 Number DIO The pin can be used as data input , It can also be output as data .6 foot CLK yes Flash Serial clock signal . The first 7 Foot for pause SPI Communication for . Last VCC It's the power pin .

chart 1
3 software design
To pass the SPI Conduct external Flash Read and write operations , We first configure the relevant clock pins , That is, the following function periph_init().

stay periph_init() in , We finished SPI,uart2 Pin configuration , And serial port 2 To initialize .
then , What we are going to do is right SPI An initialization of the interface .
void spi_init(SPI_Pad_t *cs_pad_param, SPI_Word_Mode_t bitmode, SPI_Role_t role, SPI_Polarity_Mode_t clk_pol, SPI_PHA_Mode_t pha_mode, SPI_MINT_Mode_t irq, SPI_XTAL_Freq_t freq)
The first parameter cs_pad_param Is assigned to SPI CS Signal port pin , What we use here is 0.3 foot .
The second parameter bitmode yes SPI Number of bits of operation , Yes 8.9.16.32 Bit operation mode , We use it here 8 position , So fill in SPI_MODE_8BIT.
The third parameter role Is used to configure us SPI How it works , We use the Lord here SPI, So choose SPI_ROLE_MASTER.
The first Four individual ginseng Count clk_pol yes use Come on choose Choose SPI when The clock empty Leisure extremely sex , I People use Of yes SPI_CLK_IDLE_POL_LOW, Indicates that the idle state of the serial synchronization clock is low .
Parameters pha_mode It's choice SPI Sampling edge of , What we choose here is SPI_PHA_MODE_0.
The last two parameters irq and freq They are used to configure SPI Interrupt and clock division . We choose SPI_MINT_DISABLE and SPI_XTAL_DIV_8.
That's what we're talking about SPI Initialization settings for , Of course , You can also configure according to your own needs . Yes SPI After the initialization setting , We can start reading and writing outside Flash 了 , By calling :
int32_t spi_flash_write_data (uint8_t *wr_data_ptr, uint32_t address, uint32_t size);
int32_t spi_flash_read_data (uint8_t *rd_data_ptr, uint32_t address, uint32_tsize).
4 Experimental phenomena
First , Plug it in Jlink and USB To serial port , Then open the serial port debugging assistant .
(1) Select serial port number , In our picture is COM1, This is selected according to the actual situation .
(2) Configure serial port parameters , The baud rate is 115200, Data bits 8, Stop bit 1, There is no check bit and control flow , Consistent with the figure below .
(3) Click to open the serial port ,4 Is the serial port receiving frame .
chart 2
After configuring the serial port , Open the code we provided .
(1) Click the simulation button .

chart 3
(2) Click Run code .

chart 4
When it's done , You can see the serial port debugging assistant receiving box information as follows .

chart 5
More complete learning materials and corresponding open source Suites , Please visit the official website :“ Crazy shell ”
边栏推荐
- Upgrade appium automation framework to the latest 2.0
- 怎么在中金证券购买新课理财产品?收益百分之6
- findContours
- Top 10 in China's HCI software market: Huawei, Xinhua, Shenxin, VMware, Lenovo, smartx, Inspur, Qingyun, lutanli, dawn
- Detailed explanation of ThreadLocal
- Information system project manager must recite the core examination site (47) project subcontract
- Cloud native observability tracking technology in the eyes of Baidu engineers
- 2022 chemical automation control instrument test question simulation test platform operation
- Scientific computing toolkit SciPy data interpolation
- Put apples
猜你喜欢

Sword finger offer 15. number of 1 in binary

Native applets are introduced using vant webapp

Solution: 2003 cant connect to MySQL server on * * * * and use near 'identified by' * * * * 'with grant option' at

Open source demo | release of open source example of arcall applet
Hilditch refinement (implementation I)

Five common misuse of async/await

Codeforces Round #808 (Div. 2)(A~D)

Appium element positioning - App automated testing

How to use named slots

Lenovo Filez helps Zhongshui North achieve safe and efficient file management
随机推荐
Go language error handling
[untitled]
Mitmproxy tampering with returned data
RESNET interpretation and 1 × 1 Introduction to convolution
Native applets are introduced using vant webapp
C local functions and yield statements
Hilditch refinement (implementation I)
ECCV 2022 open source | target segmentation for 10000 frames of video
ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:3306‘ (10061)
Vscode connected to the remote server cannot format the code / document (resolved)
C synchronous asynchronous callback state machine async await demo
Preview and save pictures using uni app
CAD disable a button on the toolbar (WEB version)
OpenGL (1) vertex buffer
Appium obtains and clicks coordinates, which is very easy to use when elements are inconvenient to locate
怎么在中金证券购买新课理财产品?收益百分之6
Classical review: understanding the "knowledge consistency" of neural networks (ICLR 2020)
One bite of Stream(7)
Oracle primary key auto increment setting
Overloaded & lt; for cv:: point;, But VS2010 cannot find it