STM8S105 SPI initialization

Publisher:chaohuangmeitaoLatest update time:2018-09-10 Source: eefocusKeywords:STM8S105  SPI Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The following drivers are applications of 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();
}


Keywords:STM8S105  SPI Reference address:STM8S105 SPI initialization

Previous article:STM8L151 uses hardware SPI to drive VS1003B MP3 decoding chip
Next article:STM8L IAP upgrade process record

Recommended ReadingLatest update time:2024-11-16 14:46

51 MCU Introduction - SPI Bus
UART, I2C and SPI are the three most commonly used communication protocols in microcontroller systems. 1. Introduction           SPI is a high-speed, full-duplex, synchronous communication bus. The standard SPI uses only 4 pins and is commonly used for communication between microcontrollers and EEPROM, FLASH, real-t
[Microcontroller]
stm32 study notes--spi and iic
Regarding the issue of changing the program mentioned last time, //Read ADXL345 registers //addr: register address //Return value: the value read u8 ADXL345_RD_Reg(u8 addr) { u8 temp=0;   IIC_Start();      IIC_Send_Byte(ADXL_WRITE); //Send device write instruction   temp=IIC_Wait_Ack();           IIC
[Microcontroller]
Analysis of Stm32's io port simulation spi routine
The following is the hardware circuit diagram, the main chip is stm32rbt6.   Paste the code void SPI_FLASH_Init1(void)//io初始化配置 {   GPIO_InitTypeDef GPIO_InitStructure;   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_9
[Microcontroller]
Analysis of Stm32's io port simulation spi routine
80C51 microcontroller drives UZZ9001 read and write operations by simulating SPI port
#include    #include absacc.h #include intrins.h #include math.h sbit CS = P2^0; sbit CLK = P2^1; sbit DATA= P2^2; /*Macro definition of 8155 port A, port B and control port*/ #define PA8155 XBYTE #define PB8155 XBYTE #define COM8155 XBYTE // Display code for ; unsigned char code Table ={0X0FC,
[Microcontroller]
SPI bus detailed notes
1 Introduction Protocol document download link: https://download.csdn.net/download/xiewinter/11295918 Figure 1-1 gives an overview of the SPI architecture. The main parts of the SPI are the status, control and data registers, shifter logic, baud rate generator, master/slave control logic and port control logic. 1.
[Microcontroller]
SPI bus detailed notes
NSS pin signal of stm32 spi
The NSS pin is also known as the chip select signal. As the master device, the NSS pin is high, and the slave device NSS pin is low. When the NSS pin is low, the SPI device is selected and can communicate with the master device. In STM32, the NSS signal pin of each SPI controller has two functions, namely input and ou
[Microcontroller]
STM32 SPI read and write problems
The reading and writing of stm32 SPI requires judging the flag bit just like USART unsigned char SPI1_ReadWrite(unsigned char writedat) { /* Loop while DR register in not emplty */ while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE) == RESET);   /* Send byte through the SPI1 peripheral */ SPI_I2S_SendDat
[Microcontroller]
Two methods of developing SPI with stm8s
1: void GPIO_Configuration(void) Add GPIOA configuration void GPIO_Configuration(void) {      GPIO_DeInit(GPIOD);   /* Configure PD0 (LED1) as output push-pull low (led switched on) */   GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);   /* GPIOD reset */   GPIO_DeInit(GPIOC);   /* Configure
[Microcontroller]
Two methods of developing SPI with stm8s
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号