2024-10-26 09:29 AM
Hello,
Today, I was receiving my eeprom data normally with my normally working I2C code, but when I entered debug mode, the uwtick increased on my processor, but it was not receiving my commands. The LED indicating that the code was running was not blinking. After some time I noticed that in debug mode the commands were not working but when not in debug mode it was working.
Setting & Code
static inline void EEPROM_Write(uint16_t memAddress, uint8_t* data, uint16_t dataSize) {
HAL_I2C_Mem_Write(&hi2c1, EEPROM_ADDR << 1, memAddress, I2C_MEMADD_SIZE_8BIT, data, dataSize, HAL_MAX_DELAY);
}
static inline void EEPROM_Read(uint16_t memAddress, uint8_t* data, uint16_t dataSize) {
HAL_I2C_Mem_Read(&hi2c1, EEPROM_ADDR << 1, memAddress, I2C_MEMADD_SIZE_8BIT, data, dataSize, HAL_MAX_DELAY);
}
void Main_Loop(){
/* System Init*/
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2); HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);
TIM1->CCR1 = 0; TIM1->CCR2 = 0;
Motor.M_STATUS = MOTOR_RELEASE; Motor.ControlType = CLOSE_LOOP;
Memory_Init();//M24C01 EEPROM Init //0x10 - 0x20 Parameters Address
HAL_ADCEx_Calibration_Start(&hadc);
HAL_TIM_Encoder_Start_IT(&htim2,TIM_CHANNEL_ALL);
while(1){
TIMER(); //Timer + Task Timer
Motor_Control(Motor.Rotation,Motor.Acceleration,Motor.Brake);
Timing.LoopTime = HAL_GetTick();
Timing.ElapsedTime = Timing.LoopTime - Timing.Timer;
}
}
2024-10-26 02:50 PM - edited 2024-10-26 02:53 PM
Hello,
@Sergen wrote:
but it was not receiving my commands.
Which commands? please elaborate.
@Sergen wrote:
The LED indicating that the code was running was not blinking.
I'm not seeing any LED blinking in the code
+ You are not showing how you are calling EEPROM read/write in your code.
2024-10-27 12:55 AM
static inline void TIMER(){
Timing.Timer = HAL_GetTick();
if(Timing.Timer - Timing.PrevTime >= 1){
if(Timing.TaskCounter++ >= 150){
HAL_ADC_Start_DMA(&hadc,ADC_PARAMS,3); //Index : 0 - Current 1 - Voltage 2 - Temp
POWER_Control(); //Current - Temp Control (Temp Closed)
}
if(Timing.TaskCounter >= 1000){
if(RS485_Status.Status == PROGRAM){
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_15); HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_14);
}
else{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15,GPIO_PIN_RESET); HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_14);
}
Timing.TaskCounter = 0;
}
Timing.PrevTime = Timing.Timer;
}
}
static inline void EEPROM_Write(uint16_t memAddress, uint8_t* data, uint16_t dataSize) {
HAL_I2C_Mem_Write(&hi2c1, EEPROM_ADDR << 1, memAddress, I2C_MEMADD_SIZE_8BIT, data, dataSize, HAL_MAX_DELAY); //Eeprom write method
}
static inline void EEPROM_Read(uint16_t memAddress, uint8_t* data, uint16_t dataSize) {
HAL_I2C_Mem_Read(&hi2c1, EEPROM_ADDR << 1, memAddress, I2C_MEMADD_SIZE_8BIT, data, dataSize, HAL_MAX_DELAY); //eeprom read method
}
void Memory_Init(){ //While Before calling method
EEPROM_Read(PARAM_ADDR_1,MEM_BUFFER,16); HAL_Delay(5);
EEPROM_Read(PARAM_ADDR_2,SAVED_POS,4); HAL_Delay(5);
}
Hello,
I realized there were some places I forgot to add yesterday, sorry about that.
Before the while, I call an eeprom method called Memory_Init(). When I call this method, sometimes I2C works properly, the microcontroller receives my commands or overrun etc. It returns errors, it does not loop, it does not receive all my engine, gpio and other commands, but my EEPROM chip is not broken and it does this from time to time. After opening this issue last night, I realized that this problem occurs even if I enter debug mode or not.
2024-10-28 01:38 AM
Hello @Sergen
Have you tried using the DMA process? Utilizing DMA can help avoid overrun issues.
Why are you waiting 5ms after the read operation? Is this the recommended wait time mentioned in the slave device's datasheet to ensure the device is ready after a read process?
2024-11-13 06:25 AM - edited 2024-11-13 06:26 AM
Before doing i2c read, there is a command to chek if the bus is ready or not. Try to reduce the i2c pullups. Check the return code of i2c calls. Try with reduced i2c speed(100khz)