test soft i2c write and read passed

This commit is contained in:
2025-11-18 14:37:42 +08:00
parent 73733da6dd
commit 1d75c96f74
6 changed files with 233 additions and 184 deletions

89
empty.c
View File

@@ -34,13 +34,13 @@
#include "delay.h"
#include "dfoc.h"
#include "mt6701.h"
#include "soft_i2c.h"
#include "ti_msp_dl_config.h"
#include <ctype.h>
#include <pwm.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern float angle_f;
extern bool gIsI2cError;
@@ -96,43 +96,70 @@ int main(void) {
SYSCFG_DL_init();
int count = 10;
while (count--) {
DL_GPIO_writePinsVal(LED_PORT, LED_PA0_PIN, 1);
delay_ms(100);
DL_GPIO_writePinsVal(LED_PORT, LED_PA0_PIN, 0);
delay_ms(100);
}
/* Configure DMA source, destination and size */
DL_DMA_setSrcAddr(DMA, DMA_CH1_CHAN_ID, (uint32_t)(&UART_0_INST->RXDATA));
DL_DMA_setDestAddr(DMA, DMA_CH1_CHAN_ID, (uint32_t)&gUartRxPacket[0]);
DL_DMA_setTransferSize(DMA, DMA_CH1_CHAN_ID, UART_PACKET_SIZE);
DL_DMA_enableChannel(DMA, DMA_CH1_CHAN_ID);
// DL_DMA_setSrcAddr(DMA, DMA_CH1_CHAN_ID, (uint32_t)(&UART_0_INST->RXDATA));
// DL_DMA_setDestAddr(DMA, DMA_CH1_CHAN_ID, (uint32_t)&gUartRxPacket[0]);
// DL_DMA_setTransferSize(DMA, DMA_CH1_CHAN_ID, UART_PACKET_SIZE);
// DL_DMA_enableChannel(DMA, DMA_CH1_CHAN_ID);
NVIC_EnableIRQ(UART_0_INST_INT_IRQN);
DL_TimerA_startCounter(PWM_0_INST);
// DL_TimerA_startCounter(PWM_0_INST);
NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN);
DL_TimerG_startCounter(TIMER_0_INST);
FOC_Init(12);
DL_SYSTICK_resetValue();
// NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN);
// DL_TimerG_startCounter(TIMER_0_INST);
// FOC_Init(12);
// DL_SYSTICK_resetValue();
uint32_t readback = 0xffff;
while (1) {
// DL_GPIO_togglePins(LED_PORT, LED_PA0_PIN);
// delay_ms(10);
// 开环
// velocityopenloop(Target);
// 闭环
Set_Angle(Target);
if (gCheckUART) {
gCheckUART = false;
parse_uart_cmd();
// Set_Angle(Target);
}
// delay_ms(10);
I2C_Start();
I2C_SendByte(0x06 << 1);
I2C_RecviveAck();
I2C_SendByte(0x03);
I2C_RecviveAck();
I2C_Stop();
// DL_GPIO_writePinsVal(LED_PORT, LED_PA0_PIN, 1);
// readback = DL_GPIO_readPins(LED_PORT, LED_PA0_PIN);
// printf("pa 0readback is %d \n", readback);
// delay_ms(100);
// DL_GPIO_writePinsVal(LED_PORT, LED_PA0_PIN, 0);
// readback = DL_GPIO_readPins(LED_PORT, LED_PA0_PIN);
// printf("pa0 readback is %d \n", readback);
// delay_ms(100);
// DL_GPIO_disableOutput(SOFT_I2C_PORT, SOFT_I2C_CLK_PIN);
// DL_GPIO_initDigitalInputFeatures(
// SOFT_I2C_CLK_IOMUX, DL_GPIO_INVERSION_DISABLE,
// DL_GPIO_RESISTOR_PULL_UP, DL_GPIO_HYSTERESIS_DISABLE,
// DL_GPIO_WAKEUP_DISABLE);
// DL_GPIO_disableOutput(SOFT_I2C_PORT, SOFT_I2C_SDA_PIN);
// DL_GPIO_initDigitalInputFeatures(
// SOFT_I2C_SDA_IOMUX, DL_GPIO_INVERSION_DISABLE,
// DL_GPIO_RESISTOR_PULL_UP, DL_GPIO_HYSTERESIS_DISABLE,
// DL_GPIO_WAKEUP_DISABLE);
// readback =
// DL_GPIO_readPins(SOFT_I2C_PORT, SOFT_I2C_CLK_PIN | SOFT_I2C_SDA_PIN);
// printf("soft_i2c_clk readback is %x \n", readback);
// delay_ms(100);
// // DL_GPIO_togglePins(LED_PORT, LED_PA0_PIN);
// // delay_ms(10);
// // 开环
// // velocityopenloop(Target);
// // 闭环
// Set_Angle(Target);
// if (gCheckUART) {
// gCheckUART = false;
// parse_uart_cmd();
// // Set_Angle(Target);
// }
// // delay_ms(10);
}
}