当前位置:网站首页>Hardware SPI analysis and configuration process of imx6ull bare metal development
Hardware SPI analysis and configuration process of imx6ull bare metal development
2022-04-23 00:54:00 【Swiler】
Bare metal configuration hardware SPI
The details of the SPI For the introduction of timing, please see my other article :STM32 And SPI Detailed analysis
ESPI Introduce
IMX6U Self contained SPI The peripheral is called ECSPI, The full name is Enhanced Configurable Serial Peripheral Interface,ECSPI Contains a 64x32 Receive buffer (RXFIFO) And a 64x32 Transfer buffer (TXFIFO). By data FIFOs,ECSPI Allows fast data communication with fewer software interruptions .IMX6U Yes 4 individual ESPI. The picture below is ECSPI Diagram of . By a stack of registers , Clock generator , External pins , A state machine consists of .

Characteristics are as follows :
① Full duplex synchronous serial interface .
② Configurable master / Slave mode .
③ Four chip selection signals , Support multiple slaves .
④ Both sending and receiving have a 32x64 Of FIFO.
⑤ Piece of optional signal SS/CS, Clock signal SCLK Polarity configurable .
⑥ Support DMA.
Supported modes are 3 Kind of :
① Host mode
② Slave mode
③ Low power mode
External pins
And usual SPI equally , There are MOSI、MISO、CLK、CS Pin , however ESPI Hardware chip selection pin support 4 Select an external device .( Software configuration pins can be used instead of hardware chip selection pins .)
The clock
ESPI The clock sources are 4 An option :

register
Each group SPI All have the following register groups . Include : Data receiving register 、 Data transmission register 、 Control register 、 Configuration register 、 Interrupt register 、DMA register 、 Status register 、 Sampling period control register 、 Test the control register 、 Message data register .

ECSPIx_RXDATA: Data receiving register ; because ECSPI The data receiving block of is a 64*32 Of FIFO block , Therefore, the data receiving register is used as the header in this block .
ECSPIx_TXDATA: Data transmission register ; Empathy ECSPIx_RXDATA, It is the header of the data transmission block .
ECSPIx_CONREG: Control register , To enable SPI, Configure working mode, etc .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-1vEIRyDW-1650546158115)(C:\Users\15894\AppData\Roaming\Typora\typora-user-images\image-20220421201406035.png)]
- BURST_LENGTH paragraph : Burst length , I.e. configuration SPI Burst transmission data length , Up to 2^12bit, The general configuration is 8bit
- CHANNEL_SELECT paragraph :SPI Channel selection
- DRCTL paragraph : Configure the preparation signal .0: No concern ,1: edge-triggered ,2: Level trigger
- PRE_DIVIDER paragraph : To configure SPI Clock prescaler
- POST_DIVIDER paragraph : To configure SPI The clock frequency division
- CHANNEL_MODE:SPI On off mode selection ,1: Main mode ,0: Slave mode
- SMC: Start mode control
- XCH: Configure whether to turn on SPI Burst access
- EN:SPI Enable bit ,1 Can make ,0 close
ECSPIx_CONFIGREG: Configuration register , To configure SPI Some related parameters

-
SCLK_CTL: To configure SCLK Idle state level of the signal ,4 bits , They correspond to each other 4 Channels ,0: Low level ,1: High level
-
DATA_CTL: Configure the idle state level of the data line ,4 bits , They correspond to each other 4 Channels ,0: Low level ,1: High level
-
SS_POL: Configure chip selection signal polarity ,4 bits , They correspond to each other 4 Channels ,0: Low level active ,1: High active
-
SCLK_POL: To configure SPI Clock polarity
-
SCLK_PHA: To configure SPI Clock phase
ECSPIx_INTREG: Interrupt control register , Altogether 8 A break
ECSPIx_DMAREG:DMA Control register
ECSPIx_STATREG: Status register , Defined 8 States , There were : Transmission complete 、RXFIFO overflow 、RXFIFO empty 、RXFIFO Data request 、RXFIFO be ready 、TXFIFO full 、TXFIFO Data request 、TXFIFO empty .
ECSPIx_PERIODREG: Sampling period control register
SPI Primary communication flow in host mode
- To configure CONREG and CONFIGREG register
- Configure interrupt register ( Optional )
- To configure DMA register ( Optional )
- To configure SPI The clock ( Optional )
- choice SPI passageway
- Waiting to send FIFO It's empty
- Fill the sending block ( namely TXFIFO)
- Waiting to receive FIFO There's data
- Transfer the data in the receiving block
The code analysis
C file
#include "bsp_spi.h"
#include "bsp_gpio.h"
#include "stdio.h"
/* initialization SPI */
void spi_init(ECSPI_Type *base)
{
/* To configure CONREG register * bit0 : 1 Can make ECSPI * bit3 : 1 Direction TXFIFO Turn on immediately after writing data SPI Sudden . * bit[7:4] : 0001 SPI passageway 0 Main mode , Choose... According to the actual situation , * bit[19:18]: 00 Select the channel 0 * bit[31:20]: 0x7 The burst length is 8 individual bit. */
base->CONREG = 0; /* Clear the control register first */
base->CONREG |= (1 << 0) | (1 << 3) | (1 << 4) | (7 << 20); /* To configure CONREG register */
base->CONFIGREG = 0; /* Set the channel register */
/* ECSPI passageway 0 Set up , Set the sampling period , That is, the interval between each time when reading data */
base->PERIODREG = 0X2000; /* Set the sampling period register */
/* * ECSPI Of SPI Clock configuration ,SPI The source of the clock comes from pll3_sw_clk/8=480/8=60MHz * By setting CONREG The register of PER_DIVIDER(bit[11:8]) and POST_DIVEDER(bit[15:12]) Come on * Yes SPI Clock source frequency division , Get what we want SPI The clock : * SPI CLK = (SourceCLK / PER_DIVIDER) / (2^POST_DIVEDER) * For example, we are now going to set SPI The clock is 6MHz, that PER_DIVEIDER and POST_DEIVIDER Set as follows : * PER_DIVIDER = 0X9. * POST_DIVIDER = 0X0. * SPI CLK = 60000000/(0X9 + 1) = 60000000=6MHz */
base->CONREG &= ~((0XF << 12) | (0XF << 8)); /* eliminate PER_DIVDER and POST_DIVEDER */
base->CONREG |= (0X9 << 12); /* Set up SPI CLK = 6MHz */
}
/* SPI passageway 0 send out / Receive one byte of data */
unsigned char spi_transmit_byte(ECSPI_Type *base, unsigned char txdata)
{
uint32_t spirxdata = 0;
uint32_t spitxdata = txdata;
/* Select the channel 0 */
base->CONREG &= ~(3 << 18);
base->CONREG |= (0 << 18);
while((base->STATREG & (1 << 0)) == 0){
} /* Waiting to send FIFO It's empty */
base->TXDATA = spitxdata;
while((base->STATREG & (1 << 3)) == 0){
} /* Waiting to receive FIFO There's data */
spirxdata = base->RXDATA;
return spirxdata;
}
H file
#ifndef _BSP_SPI_H
#define _BSP_SPI_H
#include "imx6ul.h"
/* Function declaration */
void spi_init(ECSPI_Type *base);
unsigned char spi_transmit_byte(ECSPI_Type *base, unsigned char txdata);
#endif
版权声明
本文为[Swiler]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230053490430.html
边栏推荐
- SynchronousQueue 源码解析
- L2-011 playing with binary tree (25 points)
- ethtool查看网卡统计信息的流程
- 关于软考,这些常见问题一定要明白
- Xamarin效果第二十二篇之录音效果
- 移动端京东商城
- Intelligent wireless transmission module, cv5200 helps UAV mesh networking, wireless communication transmission scheme
- The market structure has entered a period of restructuring, ESP has frequently "recalled", and Chinese suppliers "take advantage of the trend"
- 【蓝桥杯国赛真题18】Scratch加法选择题 青少年组 scratch蓝桥杯国赛真题和答案讲解
- C# WPF UI框架MahApps切换主题
猜你喜欢

Why should I object to DBA's participation in business (issuing reports / changing data)

德勤2022技术趋势:IT自我颠覆、技术跨界融合创新

Amazon Aurora's ability to read and write: shardingsphere proxy

IMX6ULL裸机开发之EPIT周期性定时器分析及配置过程

【服务器数据恢复】服务器硬盘进水后服务器崩溃的数据恢复案例

IMX6ULL裸机开发之硬件IIC分析及配置过程

Xamarin effect Chapter 22 recording effect

Alternative scheme of 24V ~ 48V magnetic absorption track lamp fs2459 to mp2459

DCB "first brother" xianruida, what does it rely on to raise the value curve?

C# WPF UI框架MahApps切换主题
随机推荐
Binary search tree from preorder to preorder and postorder
DCB“一哥”先瑞达,靠什么拉升价值曲线?
Android international area code, registered mobile phone number code and list of common cities, Android memory optimization interview
[ACTF2020 新生赛]Include
idea中使用thymeleaf 模板 <img th:src=“${map.user.headerUrl}“ 报错Cannot resolve ‘user‘
From construction to governance, the industry's first white paper on microservice governance technology was officially released (including a free download link)
Deep learning basic learning - RNN and ltsm
[Blue Bridge Cup real question 18] scratch addition multiple-choice question youth group scratch Blue Bridge Cup real question and answer explanation
Partial ways of converting JSP to thymeleaf format
安全用电管理平台在靖边博物馆安全用电管理系统的应用
命令行修改电脑IP
The more "intelligent" the machine is, the easier it is for data taggers to be eliminated? Manfu Technology
Mobile Jingdong Mall
L2-020 功夫传人 (25 分)
[HCTF 2018]admin
What is tooljet and how about it—— Evaluation of low code development platform
L2-013 red alarm (25 points)
德勤2022技术趋势:IT自我颠覆、技术跨界融合创新
L2-002 linked list weight removal (25 points)
C#/. Net uses questpdf operation to generate PDF faster and more efficient!