add config.h ; try to OpenLoop control, not passed

This commit is contained in:
2025-11-13 15:16:24 +08:00
parent c67d13de54
commit ab6d7c0dd9
9 changed files with 133 additions and 35 deletions

View File

@@ -2,10 +2,14 @@
#include "ti_msp_dl_config.h"
#include "uart_redircet.h"
#include "stdio.h"
#include "config.h"
volatile int16_t angle;
volatile float angle_f;
volatile float angle_f_rad;
volatile bool gIsI2cError = false;
/* Data sent to the Target */
uint8_t gTxPacket[I2C_TX_PACKET_SIZE] =
{
@@ -13,7 +17,7 @@ uint8_t gTxPacket[I2C_TX_PACKET_SIZE] =
};
/* Data received from Target */
volatile uint8_t gRxPacket[I2C_RX_PACKET_SIZE];
volatile uint8_t gRxPacket[I2C_RX_PACKET_SIZE] = {0};
/* I2C clock configuration */
DL_I2C_ClockConfig gI2CclockConfig;
@@ -46,8 +50,13 @@ void MT6701_iic_read_angel(void)
* gDelayCycles = 3 I2C functional clock cycles
* gDelayCycles = 3 * I2C clock divider * (CPU clock freq / I2C clock freq)
*/
gDelayCycles = (3 * (gI2CclockConfig.divideRatio + 1)) *
gDelayCycles = (5 * (gI2CclockConfig.divideRatio + 1)) *
(CPUCLK_FREQ / gClockSelFreq);
if(DEBUG_ENABLED & DEBUG_MT_ENABLED)
{
printf("i2c before writing -------\n");
}
/*
* Fill FIFO with data. This example will send a MAX of 8 bytes since it
@@ -66,6 +75,11 @@ void MT6701_iic_read_angel(void)
DL_I2C_startControllerTransfer(I2C_1_INST, I2C_TARGET_ADDRESS,
DL_I2C_CONTROLLER_DIRECTION_TX, I2C_TX_PACKET_SIZE);
if(DEBUG_ENABLED & DEBUG_MT_ENABLED)
{
printf("i2c writing done -------\n");
}
/* Workaround for errata I2C_ERR_13 */
delay_cycles(gDelayCycles);
@@ -78,7 +92,12 @@ void MT6701_iic_read_angel(void)
if(DL_I2C_getControllerStatus(I2C_1_INST) &
DL_I2C_CONTROLLER_STATUS_ERROR)
{
printf("i2c error --------------------------------------------------------------------------------\n");
gIsI2cError = true;
if(DEBUG_ENABLED & DEBUG_MT_ENABLED)
{
printf("i2c error ------------------------------------------\n");
}
/* LED will remain high if there is an error */
__BKPT(0);
return;
@@ -92,6 +111,11 @@ void MT6701_iic_read_angel(void)
/* Add delay between transfers */
delay_cycles(1000);
if(DEBUG_ENABLED & DEBUG_MT_ENABLED)
{
printf("i2c before reading -------\n");
}
/* Send a read request to Target */
DL_I2C_startControllerTransfer(I2C_1_INST, I2C_TARGET_ADDRESS,
DL_I2C_CONTROLLER_DIRECTION_RX, I2C_RX_PACKET_SIZE);
@@ -106,6 +130,13 @@ void MT6701_iic_read_angel(void)
;
gRxPacket[i] = DL_I2C_receiveControllerData(I2C_1_INST);
}
if(DEBUG_ENABLED & DEBUG_MT_ENABLED)
{
printf("i2c reading done -------\n");
}
}
volatile float Last_ts = 0.0;
volatile float last_angle = 0.0;