2019-09-17 03:14 AM
I am using STMCubeMx V5.2.1& Atollic True studio V9.2 for generating code using HAL libraries/functions . The MCU is STM32F103C8T6(Blue pill board).
I am trying to write & read the one byte data from eeprom AT24CM02 using I2C communication
I used PB6 & PB7 pins in the board for I2C.
& st-link to program the board
Slave address = 0xA0 for AT24CM02
I used HAL_I2C_mem write/read function.
Observations: Using an oscilloscope, i can see that there is no clock signal on SCL pin. The voltage at the SCL pin is always low. The voltage on the SDA pin is always High.
But with same board and same hardware connection it is working with Arduino IDE & i can see the clock signal in oscilloscope.
I am not able understand what is the exact problem with software generated by Cube Mx .
because of this issue my project is not moving forward, so any one can help me to solve this issue it will be great help.
Below I have copied the code from main() function:
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "i2c.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
#define EEPROM_ADDRESS 0xA0
uint8_t data_write=50;
uint8_t read_data=0;
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
HAL_I2C_Mem_Write(&hi2c1,(uint16_t)EEPROM_ADDRESS, 0, 0xFF, &data_write, 1 , 10);
HAL_Delay(10);
HAL_I2C_Mem_Read(&hi2c1,(uint16_t)EEPROM_ADDRESS, 0 , 0xFF, &read_data ,1 , 1);
// sprintf(data_to_read,"%d",read_data);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
//read_data=50;
HAL_I2C_Mem_Write(&hi2c1,(uint16_t)EEPROM_ADDRESS, 0, 0xFF, &data_write, 1 , 10);
HAL_Delay(10);
HAL_I2C_Mem_Read(&hi2c1,(uint16_t)EEPROM_ADDRESS, 0 , 0xFF, &read_data ,1 , 1);
if(read_data==50)
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
else
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_RESET);
HAL_Delay(500);
}
/* USER CODE END 3 */
}
Thanks & Regards
Yogesh