Compare commits
2 Commits
488e6ea813
...
3e063e12b0
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e063e12b0 | |||
| 4a2c9d01b2 |
@ -12,3 +12,4 @@
|
|||||||
platform = ch32v
|
platform = ch32v
|
||||||
board = genericCH32V003F4P6
|
board = genericCH32V003F4P6
|
||||||
framework = noneos-sdk
|
framework = noneos-sdk
|
||||||
|
monitor_speed = 115200
|
||||||
|
|||||||
@ -44,15 +44,9 @@ void ADCConfig(void) {
|
|||||||
ADC_InjectedChannelConfig(ADC1, ADC_Channel_7, 4, ADC_SampleTime_241Cycles);
|
ADC_InjectedChannelConfig(ADC1, ADC_Channel_7, 4, ADC_SampleTime_241Cycles);
|
||||||
ADC_ExternalTrigInjectedConvCmd(ADC1, DISABLE);
|
ADC_ExternalTrigInjectedConvCmd(ADC1, DISABLE);
|
||||||
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;
|
NVIC_EnableIRQ(ADC_IRQn);
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|
||||||
NVIC_Init(&NVIC_InitStructure);
|
|
||||||
|
|
||||||
// ADC_Calibration_Vol(ADC1, ADC_CALVOL_75PERCENT);
|
|
||||||
// ADC_Calibration_Vol(ADC1, ADC_CALVOL_50PERCENT);
|
|
||||||
ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE);
|
ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE);
|
||||||
|
|
||||||
ADC_Cmd(ADC1, ENABLE);
|
ADC_Cmd(ADC1, ENABLE);
|
||||||
|
|
||||||
ADC_ResetCalibration(ADC1);
|
ADC_ResetCalibration(ADC1);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#include "i2c_slave.h"
|
#include "i2c_slave.h"
|
||||||
#include "uart_driver.h"
|
#include <stdio.h>
|
||||||
|
|
||||||
// https://pallavaggarwal.in/2023/10/05/ch32v003-programming-i2c-eeprom/
|
// https://pallavaggarwal.in/2023/10/05/ch32v003-programming-i2c-eeprom/
|
||||||
void i2c_init() {
|
void i2c_init() {
|
||||||
@ -44,20 +44,20 @@ void I2C1_EV_IRQHandler(void) {
|
|||||||
STAR2 = I2C1->STAR2;
|
STAR2 = I2C1->STAR2;
|
||||||
|
|
||||||
if (STAR1 & I2C_STAR1_ADDR) { // Start event
|
if (STAR1 & I2C_STAR1_ADDR) { // Start event
|
||||||
UartStringSend("Start Event\r\n");
|
printf("Start Event\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STAR1 & I2C_STAR1_RXNE) { // Write event
|
if (STAR1 & I2C_STAR1_RXNE) { // Write event
|
||||||
UartStringSend("Write Event\r\n");
|
printf("Write Event\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STAR1 & I2C_STAR1_TXE) { // Read event
|
if (STAR1 & I2C_STAR1_TXE) { // Read event
|
||||||
UartStringSend("Read Event\r\n");
|
printf("Read Event\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STAR1 & I2C_STAR1_STOPF) { // Stop event
|
if (STAR1 & I2C_STAR1_STOPF) { // Stop event
|
||||||
I2C1->CTLR1 &= ~(I2C_CTLR1_STOP); // Clear stop
|
I2C1->CTLR1 &= ~(I2C_CTLR1_STOP); // Clear stop
|
||||||
UartStringSend("Stop Event\r\n");
|
printf("Stop Event\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,17 +66,17 @@ void I2C1_ER_IRQHandler(void) {
|
|||||||
|
|
||||||
if (STAR1 & I2C_STAR1_BERR) { // Bus error
|
if (STAR1 & I2C_STAR1_BERR) { // Bus error
|
||||||
I2C1->STAR1 &= ~(I2C_STAR1_BERR); // Clear error
|
I2C1->STAR1 &= ~(I2C_STAR1_BERR); // Clear error
|
||||||
UartStringSend("Bus error\r\n");
|
printf("Bus error\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STAR1 & I2C_STAR1_ARLO) { // Arbitration lost error
|
if (STAR1 & I2C_STAR1_ARLO) { // Arbitration lost error
|
||||||
I2C1->STAR1 &= ~(I2C_STAR1_ARLO); // Clear error
|
I2C1->STAR1 &= ~(I2C_STAR1_ARLO); // Clear error
|
||||||
UartStringSend("Arbitration lost error\r\n");
|
printf("Arbitration lost error\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STAR1 & I2C_STAR1_AF) { // Acknowledge failure
|
if (STAR1 & I2C_STAR1_AF) { // Acknowledge failure
|
||||||
I2C1->STAR1 &= ~(I2C_STAR1_AF); // Clear error
|
I2C1->STAR1 &= ~(I2C_STAR1_AF); // Clear error
|
||||||
UartStringSend("Ack Failure\r\n");
|
printf("Ack Failure\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include "neopixel_driver.h"
|
#include "neopixel_driver.h"
|
||||||
// #include "bit_bang_neopixel.h"
|
// #include "bit_bang_neopixel.h"
|
||||||
#include "uart_driver.h"
|
|
||||||
#include "hall_driver.h"
|
#include "hall_driver.h"
|
||||||
#include "i2c_slave.h"
|
#include "i2c_slave.h"
|
||||||
|
|
||||||
@ -21,8 +20,8 @@ int main(void)
|
|||||||
// allow some time to enter flash mode, in case something gets screwed up
|
// allow some time to enter flash mode, in case something gets screwed up
|
||||||
Delay_Ms(1000);
|
Delay_Ms(1000);
|
||||||
|
|
||||||
USARTx_CFG();
|
USART_Printf_Init(115200);
|
||||||
UartStringSend("Hello World!\r\n");
|
printf("Hello World!\r\n");
|
||||||
|
|
||||||
SPINeoPixelDriverInit();
|
SPINeoPixelDriverInit();
|
||||||
// BBNeoPixelDriverInit();
|
// BBNeoPixelDriverInit();
|
||||||
@ -59,9 +58,7 @@ int main(void)
|
|||||||
|
|
||||||
adcFlag = 0;
|
adcFlag = 0;
|
||||||
|
|
||||||
char buffer[64] = {0};
|
// printf("%d\t%d\t%d\t%d\r\n", adc_readings[0], adc_readings[1], adc_readings[2], adc_readings[3]);
|
||||||
// sprintf(buffer, "%d\t%d\t%d\t%d\r\n", adc_readings[0], adc_readings[1], adc_readings[2], adc_readings[3]);
|
|
||||||
// UartStringSend(buffer);
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (adc_readings[i] > adc_calibration_values[i] + 5) {
|
if (adc_readings[i] > adc_calibration_values[i] + 5) {
|
||||||
|
|||||||
@ -1,56 +0,0 @@
|
|||||||
#include "uart_driver.h"
|
|
||||||
|
|
||||||
void USARTx_CFG(void) {
|
|
||||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
|
||||||
USART_InitTypeDef USART_InitStructure = {0};
|
|
||||||
NVIC_InitTypeDef NVIC_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_ITConfig(USART1, USART_IT_RXNE, ENABLE);
|
|
||||||
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|
||||||
NVIC_Init(&NVIC_InitStructure);;
|
|
||||||
|
|
||||||
USART_Cmd(USART1, ENABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UartBufferSend(uint8_t* buffer, uint16_t length)
|
|
||||||
{
|
|
||||||
uint16_t i = 0;
|
|
||||||
for(i =0; i < length; i++)
|
|
||||||
{
|
|
||||||
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); /* waiting for sending finish */
|
|
||||||
USART_SendData(USART1, buffer[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void UartStringSend(char* string) {
|
|
||||||
uint16_t i = 0;
|
|
||||||
while (string[i] != '\0') {
|
|
||||||
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); /* waiting for sending finish */
|
|
||||||
USART_SendData(USART1, string[i]);
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
#ifndef UART_DRIVER_H
|
|
||||||
#define UART_DRIVER_H
|
|
||||||
|
|
||||||
#include <ch32v00x.h>
|
|
||||||
|
|
||||||
void USARTx_CFG(void);
|
|
||||||
void UartBufferSend(uint8_t* buffer, uint16_t length);
|
|
||||||
void UartStringSend(char* string);
|
|
||||||
|
|
||||||
#endif // UART_DRIVER_H
|
|
||||||
Loading…
Reference in New Issue
Block a user