2019-01-09 06:11 AM
Hello
I am using STM32F100C4T6B and i want to read information from my module GY-50 L3G4200D using I2C and sending it by uart to my computer. I can not do it by SWD. Im using STM32CubeMX and System Workbench for STM32. I know for sure that communication by UART works because i tested it but i cant get any info from my gyro. I am pretty sure everything is connected as it should be. I do not know what to do. Please help me. Here is a part of my code
#define L3G4200D_ACC_ADDRESS (0x69 << 1) // adres akcelerometru
// adres akcelerometru
#define L3G4200D_ACC_CTRL_REG1 0x20 // rejestr ustawien 1
#define L3G4200D_ACC_CTRL_REG4 0x23 // rejestr ustawien 1
#define WHO_AM_I 0x0F
#define L3G4200D_ACC_Z_H_A 0x2D // starszy bajt danych osi z
//CTRL_REG1 = [DR1][DR0][BW1][BW0][PD][Zen][Yen][Xen]
// Maski bitowe
#define L3G4200D_ACC_100HZ 0x0F
#define L3G4200D_ACC_DPS 0x20
// Zmienne
uint8_t Data=0;
int8_t Zaxis =0;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_I2C1_Init(void);
static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/*void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
static uint16_t cnt = 0; //Licznik wysylanych wiadomosci
uint8_t data [50];//Tablica przechowujaca wysylana wiadomosc
uint16_t size = 0;//Rozmiar wysylanej wiadomosci
++cnt; // Zwiekszenia licznika wysylanych wiadomosci
size = sprintf(data, "Liczba wysylanych wiadomosc: %d.\n\r", cnt); // Stworzenie wiadomosci do
wyslania oraz przypisanie ilosci wysylanych znakow do zmiennej size
HAL_UART_Transmit_IT(&huart1, data, size);// Rozpoczecie nadawania danych z wykorzystaniem przerwan
}*/
/* 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();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
uint8_t Settings = L3G4200D_ACC_100HZ;
uint8_t Settings1 = L3G4200D_ACC_DPS;
HAL_I2C_Mem_Write(&hi2c1, L3G4200D_ACC_ADDRESS, L3G4200D_ACC_CTRL_REG1, 1, &Settings, 1, 100);
HAL_I2C_Mem_Write(&hi2c1, L3G4200D_ACC_ADDRESS, L3G4200D_ACC_CTRL_REG4, 1, &Settings1, 1, 100);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_I2C_Mem_Read(&hi2c1, L3G4200D_ACC_ADDRESS, L3G4200D_ACC_Z_H_A , 1, &Data, 1, 100);
Zaxis = Data << 8;
uint8_t data1 [50];//Tablica przechowujaca wysylana wiadomosc
uint16_t size = 0;//Rozmiar wysylanej wiadomosci
size = sprintf(data1, "Odczyt Z: %d.\n\r", Zaxis); // Stworzenie wiadomosci do
HAL_UART_Transmit_IT(&huart1, data1, size);// Rozpoczecie nadawania danych z wykorzystaniem przerwan
/* USER CODE END 3 */
}
}