From 2b7cc2abd6ca3eacfa00e8da8c03fff28ae52560 Mon Sep 17 00:00:00 2001 From: ElicMagus Date: Mon, 8 Apr 2024 16:59:32 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B0=20SPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .settings/org.eclipse.core.resources.prefs | 13 +++++ User/main.c | 65 +--------------------- User/spi.c | 10 ++++ User/spi.h | 16 ++++++ 4 files changed, 40 insertions(+), 64 deletions(-) create mode 100644 User/spi.c create mode 100644 User/spi.h diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 7ff0273..f27d23b 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,2 +1,15 @@ eclipse.preferences.version=1 +encoding//.settings/org.eclipse.core.resources.prefs=GBK +encoding//Debug/debug.h=GBK +encoding//Peripheral/inc/ch32v00x.h=GBK +encoding//Peripheral/inc/ch32v00x_spi.h=GBK +encoding//Peripheral/src/ch32v00x_spi.c=GBK +encoding//Startup/startup_ch32v00x.S=GBK +encoding//User/ch32v00x_conf.h=GBK +encoding//User/ch32v00x_it.c=GBK +encoding//User/ch32v00x_it.h=GBK encoding//User/main.c=GBK +encoding//User/spi.c=GBK +encoding//User/spi.h=GBK +encoding//User/system_ch32v00x.c=GBK +encoding//User/system_ch32v00x.h=GBK diff --git a/User/main.c b/User/main.c index a0e6b3f..4ebd769 100644 --- a/User/main.c +++ b/User/main.c @@ -1,70 +1,8 @@ -/********************************** (C) COPYRIGHT ******************************* - * File Name : main.c - * Author : WCH - * Version : V1.0.0 - * Date : 2023/12/25 - * Description : Main program body. - ********************************************************************************* - * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. - * Attention: This software (modified or not) and binary are used for - * microcontroller manufactured by Nanjing Qinheng Microelectronics. - *******************************************************************************/ - -/* - *@Note - *Multiprocessor communication mode routine: - *Master:USART1_Tx(PD5)\USART1_Rx(PD6). - *This routine demonstrates that USART1 receives the data sent by CH341 and inverts - *it and sends it (baud rate 115200). - * - *Hardware connection:PD5 -- Rx - * PD6 -- Tx - * - */ - #include "debug.h" -/* Global define */ -/* Global Variable */ -vu8 val; - -/********************************************************************* - * @fn USARTx_CFG - * - * @brief Initializes the USART2 & USART3 peripheral. - * - * @return none - */ -void USARTx_CFG(void) -{ - GPIO_InitTypeDef GPIO_InitStructure = {0}; - USART_InitTypeDef USART_InitStructure = {0}; - - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_USART1, ENABLE); - - /* USART1 TX-->D.5 RX-->D.6 */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; - GPIO_Init(GPIOD, &GPIO_InitStructure); - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_Init(GPIOD, &GPIO_InitStructure); - - USART_InitStructure.USART_BaudRate = 115200; - USART_InitStructure.USART_WordLength = USART_WordLength_8b; - USART_InitStructure.USART_StopBits = USART_StopBits_1; - USART_InitStructure.USART_Parity = USART_Parity_No; - USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; - USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; - - USART_Init(USART1, &USART_InitStructure); - USART_Cmd(USART1, ENABLE); -} - /********************************************************************* * @fn main * @@ -94,8 +32,7 @@ int main(void) { /* waiting for receiving finish */ } - val = (USART_ReceiveData(USART1)); - USART_SendData(USART1, ~val); + while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET) { /* waiting for sending finish */ diff --git a/User/spi.c b/User/spi.c new file mode 100644 index 0000000..b6d571a --- /dev/null +++ b/User/spi.c @@ -0,0 +1,10 @@ +/* + * spi.c + * + * Created on: Apr 8, 2024 + * Author: NikmaOS-W + */ + + + + diff --git a/User/spi.h b/User/spi.h new file mode 100644 index 0000000..6b26cf7 --- /dev/null +++ b/User/spi.h @@ -0,0 +1,16 @@ +/* + * spi.h + * + * Created on: Apr 8, 2024 + * Author: NikmaOS-W + */ + +#ifndef USER_SPI_H_ +#define USER_SPI_H_ +SPI_InitTypeDef DAC_spi; + +void DAC_spi_Init + + + +#endif /* USER_SPI_H_ */