当前位置:网站首页>Comparison between hardware SPI and software analog SPI rate
Comparison between hardware SPI and software analog SPI rate
2022-07-28 01:58:00 【freemote】
1、 Preface
This article USES the AT32F425 drive RC522 To test SPI1 Rate , About RC522 The detailed code operation of can be found in the post 【GD32L233C-START】 Hardware SPI1 drive RC522.
2、 About AT32F425 Of SPI

AT32F425 The series has at most 3 individual spi, This article USES the SPI1.
3、SPI1 The maximum rate of

SPI1 Hang on APB2 On the bus ,APB2 The maximum speed of the bus is 96MHz;
SPI The maximum rate of is fPCLK/2, namely 48Mhz.
4、 Code implementation
/*SPI1 :
PA4/CS
PA5/SCK
PA6/MISO
PA7/MOSI
*/
(1) simulation SPI
#define SET_SPI_CS() gpio_bits_set(GPIOA, GPIO_PINS_4)
#define CLR_SPI_CS() gpio_bits_reset(GPIOA, GPIO_PINS_4)
#define SET_SPI_SCLK() gpio_bits_set(GPIOA,GPIO_PINS_5)
#define CLR_SPI_SCLK() gpio_bits_reset(GPIOA,GPIO_PINS_5)//SCL=SCLK
#define SET_SPI_MOSI() gpio_bits_set(GPIOA,GPIO_PINS_7)
#define CLR_SPI_MOSI() gpio_bits_reset(GPIOA,GPIO_PINS_7)//SDO=MOSI
#define READ_SPI_MISO() gpio_input_data_bit_read(GPIOA,GPIO_PINS_6) //SDI=MISO
void SpiIoInit(void)
{
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
gpio_init_type gpio_initstructure;
/* configure the lcd gpio */
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_initstructure.gpio_mode = GPIO_MODE_OUTPUT;
gpio_initstructure.gpio_pins = GPIO_PINS_4|GPIO_PINS_5|GPIO_PINS_7;
gpio_initstructure.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_initstructure);
gpio_bits_set(GPIOA,GPIO_PINS_4|GPIO_PINS_5|GPIO_PINS_7);
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_initstructure.gpio_mode = GPIO_MODE_INPUT;
gpio_initstructure.gpio_pins = GPIO_PINS_6;
gpio_initstructure.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_initstructure);
gpio_bits_set(GPIOA,GPIO_PINS_6);
}
uint8_t SPIWriteByte(uint8_t dat)
{
uint16_t ret=0;
u8 i;
CLR_SPI_CS();
for(i=0;i<8;i++)
{
if(dat&0x80)
{
SET_SPI_MOSI();
}
else
{
CLR_SPI_MOSI();
}
dat<<=1;
// delay_us(1);
SET_SPI_SCLK();
ret<<=1;
if(READ_SPI_MISO())
{
ret+=1;
}
// delay_us(1);
CLR_SPI_SCLK();
}
SET_SPI_CS();
return (ret&0x0ff);
}
(2) Hardware SPI
void SpiIoInit(void)
{
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
gpio_initstructure.gpio_mode = GPIO_MODE_OUTPUT;
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_initstructure.gpio_pins = GPIO_PINS_4;
gpio_init(GPIOA, &gpio_initstructure);
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE5, GPIO_MUX_0);
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE6, GPIO_MUX_0);
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE7, GPIO_MUX_0);
gpio_default_para_init(&gpio_initstructure);
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_initstructure.gpio_pins = GPIO_PINS_5;
gpio_init(GPIOA, &gpio_initstructure);
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_initstructure.gpio_pins = GPIO_PINS_6;
gpio_init(GPIOA, &gpio_initstructure);
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_initstructure.gpio_pins = GPIO_PINS_7;
gpio_init(GPIOA, &gpio_initstructure);
spi_init_type spi_init_struct;
crm_periph_clock_enable(CRM_SPI1_PERIPH_CLOCK, TRUE);
spi_default_para_init(&spi_init_struct);
spi_init_struct.transmission_mode = SPI_TRANSMIT_FULL_DUPLEX;
spi_init_struct.master_slave_mode = SPI_MODE_MASTER;
spi_init_struct.mclk_freq_division = SPI_MCLK_DIV_8;
spi_init_struct.first_bit_transmission = SPI_FIRST_BIT_MSB;
spi_init_struct.frame_bit_num = SPI_FRAME_8BIT;
spi_init_struct.clock_polarity = SPI_CLOCK_POLARITY_LOW;
spi_init_struct.clock_phase = SPI_CLOCK_PHASE_1EDGE;
spi_init_struct.cs_mode_selection = SPI_CS_SOFTWARE_MODE;
spi_init(SPI1, &spi_init_struct);
spi_enable(SPI1, TRUE);
}
uint8_t SPIWriteByte(uint8_t dat)
{
uint16_t ret=0;
CLR_SPI_CS();
while(spi_i2s_flag_get(SPI1, SPI_I2S_TDBE_FLAG) == RESET) {
};
spi_i2s_data_transmit(SPI1, dat);
while(spi_i2s_flag_get(SPI1, SPI_I2S_RDBF_FLAG) == RESET) {
};
ret=spi_i2s_data_receive(SPI1);
SET_SPI_CS();
return (ret&0x0ff);
}
Use hardware SPI When testing ,RC522 The maximum speed of can only reach 12MHZ, That is to say 8 frequency division , The rate is too high, which leads to communication failure .
5、 Rate measurement
Here, use an oscilloscope directly CLK Waveform of , Grasp the whole with logical analysis SPI Waveform of .
(1) simulation SPI

It can be seen that , Using simulation SPI The time is 1.8MHz, Grabbing with logic analyzer is also the result .
(2) Hardware SPI

It can be seen that , Use hardware SPI The time is 12MHz, Consistent with the software settings , Grabbing with logic analyzer is also the result .
Comprehensive comparative measurement , You can find , Hardware SPI The speed is much higher than that of software SPI, So in order to improve cpu Utilization ratio , Try to use hardware SPI.
边栏推荐
- 开源飞控(PX4、ardupilot)
- Gbase 8C annotation information function
- Fiddler 手机抓包代理设置(针对华为荣耀60S)
- Data warehouse construction - DWS floor
- Flink 在 讯飞 AI 营销业务的实时数据分析实践
- Gbase 8C backup control function (IV)
- FreeRTOS内核小结
- Modify the request path using the streaming API of gateway
- unreal ue4.27 switchboard 移植出引擎流程
- GBase 8c 服务器信号函数
猜你喜欢

Fiddler 手机抓包代理设置(针对华为荣耀60S)

Establishment of elk log analysis system

Leetcode high frequency question 128. the longest continuous sequence, which is often tested in interviews with Internet companies

26. Abstraction and template ideas

The petrochemical industry is facing the tide of rising prices, and the digital dealer distribution system platform enables dealers and stores

leetcode: 515. 在每个树行中找最大值

硬件SPI与软件模拟SPI速率对比

Open source flight control (Px4, ardupilot)

Brushes and brushes

LeetCode高频题128. 最长连续序列,经常被互联网大厂面试考到
随机推荐
2022 software testing skills robotframework + selenium library + Jenkins web Keyword Driven Automation practical tutorial
处理数据 给数据换名字
Leetcode: 515. Find the maximum value in each tree row
基于 Flink CDC 实现海量数据的实时同步和转换
A Tiger's Tale
Hcip day 15
Unity 通用红点系统
GBase 8c 事务ID和快照(六)
机器学习如何做到疫情可视化——疫情数据分析与预测实战
After learning the loop, I came across the problem of writing factorial of N, which caused a series of problems, including some common pitfalls for beginners, and how to simplify the code
Fiddler 手机抓包代理设置(针对华为荣耀60S)
JS数字精度丢失的原因及解决方案
Leetcode's 83rd biweekly match
"Do you" want to be a test / development programmer? We strive to sprout
Leveraging the blue ocean of household appliances consumption with "digital channels", the dealer online system enables enterprises to further their business
嵌入式经典通信协议
HRD 1. 一个简单而靠谱的HRD的检测方法
How tormenting are weekly and monthly reports? Universal report template recommended collection! (template attached)
Interview question 01.08. Zero matrix
爬虫学习的一个综合案例——访问网站