Hi Paul,
Thanks for the info on format EW_PIXEL_FORMAT_RGB565 (optional). I used it to create the bitmap EwCreateBitmap() invocation fr RGB565.
I am struggling with UART, SPI and I2C. I need these drivers to read the data from the Camera Sensor.
1. I got the UART to work in my native code using the UART_HandleTypeDef UART_Handle; from ew_bsb_console.c. In my native code :
HAL_UART_Transmit(&huart1, data,10,100); Does not work, because huart1 handle I brought it in from Cube MX
HAL_UART_Transmit( &UART_Handle, data,4,10); Works, using UART_Handle, I can get characters to transmitted on the UART.
2. For SPI, I created my own initialization drivers ew_bsp_spi2.c/h I use the SPI read and Write using the : HAL_SPI_Transmit and HAL_SPI_Recieve functions with the handle hspi2. This seems to work and I can read and write an SPI register in my external device. I'm not sure if there is a pre-existing SPI handle and initializer that I should use so I don't change any system settings in EW?.
uint8_t bus_read(int address)
{
uint8_t value;
uint8_t spiData1[2];
HAL_GPIO_WritePin(GPIOI, GPIO_PIN_3,GPIO_PIN_RESET);
spiData1[0]= address; //spiData[0][0] ;0x40;
HAL_SPI_Transmit(&hspi2,spiData1, 1, 1);
HAL_SPI_Receive(&hspi2, &spiData1[1], 1, 1);
HAL_GPIO_WritePin(GPIOI, GPIO_PIN_3,GPIO_PIN_SET);
value = spiData1[1];
return value;
}
uint8_t bus_write(int address,int value)
{
uint8_t spiData1[2];
HAL_GPIO_WritePin(GPIOI, GPIO_PIN_3,GPIO_PIN_RESET);
spiData1[0] = address;
spiData1[1] = value;
HAL_SPI_Transmit(&hspi2, spiData1, 2, 1);
HAL_GPIO_WritePin(GPIOI, GPIO_PIN_3,GPIO_PIN_SET);
return 1;
}
3. As for the I2C I have a problem. I created ew_bsp_I2c_ar.c/h and put it in Makefiel. I got the initialization code from CubeMx and put the initialization routine in stm32746g_discovery.c. This is definitely NOT Working. The handle I copied for the I2C from CubeMx I put in stm32746g_discovery.c. and it is: I2C_HandleTypeDef hi2c1; See my code snippets below. After this initialization, I use the HAL functions in my native code to read and write to I2C (See last code snippet). Looking in the stm32746g_discovery.c.there seems to be already existing initialization with a different handle name for I2C and the handle name which could be one of these two in the code snippet belwo:
This code below is a section from stm32746g_discovery.c
static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler)
{
if(HAL_I2C_GetState(i2c_handler) == HAL_I2C_STATE_RESET)
{
if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler))
{
/* Audio and LCD I2C configuration */
i2c_handler->Instance = DISCOVERY_AUDIO_I2Cx;
}
else
{
/* External, camera and Arduino connector I2C configuration */
i2c_handler->Instance = DISCOVERY_EXT_I2Cx;
}
i2c_handler->Init.Timing = DISCOVERY_I2Cx_TIMING;
i2c_handler->Init.OwnAddress1 = 0;
i2c_handler->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
i2c_handler->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
i2c_handler->Init.OwnAddress2 = 0;
i2c_handler->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
i2c_handler->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
/* Init the I2C */
I2Cx_MspInit(i2c_handler);
HAL_I2C_Init(i2c_handler);
}
}
The code below is my own generated code ew_bsp_i2c_ar.h/c
/*******************************************************************************
*
* E M B E D D E D W I Z A R D P R O J E C T
*
* Copyright (c) TARA Systems GmbH
* written by Paul Banach and Manfred Schweyer
*
********************************************************************************
*
* This software is delivered "as is" and shows the usage of other software
* components. It is provided as an example software which is intended to be
* modified and extended according to particular requirements.
*
* TARA Systems hereby disclaims all warranties and conditions with regard to the
* software, including all implied warranties and conditions of merchantability
* and non-infringement of any third party IPR or other rights which may result
* from the use or the inability to use the software.
*
********************************************************************************
*
* DESCRIPTION:
* This file is part of the interface (glue layer) between an Embedded Wizard
* generated UI application and the board support package (BSP) of a dedicated
* target.
* This template provides access to some LEDs and buttons of the board.
*
*******************************************************************************/
//ew_bsp_i2c_ar.h
#ifndef EW_BSP_I2C_AR_H
#define EW_BSP_I2C_AR_H
#ifdef __cplusplus
extern "C"
{
#endif
/*******************************************************************************
* FUNCTION:
* void EwBspI2c1_ar_Init( void );
*
* DESCRIPTION:
* Configures one I2C of the board used for applications.
*
* ARGUMENTS:
* None
*
* RETURN None:
* None
*
*******************************************************************************/
// Armen Added
/* ------------------ I2C ---------------- */
void EwBspI2c1_ar_Init( void );
void BSP_I2C1_Init (void );
#ifdef __cplusplus
}
#endif
#endif /* EW_BSP_I2C_AR_H */
/* msy */
//ew_bsp_adc_ar.c
#include "ewconfig.h"
#include "stm32f7xx_hal.h"
#include "stm32746g_discovery.h"
#include "ew_bsp_i2c_ar.h"
void EwBspI2c1_ar_Init( void )
{
//BSP_ADC_Init( EW_ADC );
BSP_I2C1_Init ( );
}
/* msy */
The code below Is my modification of stm32746g_discovery.c where I initialize the I2C with my own hi2c1 instance handler.
// part of stm32746g_discovery.c
// I2C 1 Init
//static void MX_I2C1_Init(void);
void BSP_I2C1_Init( void )
{
MX_I2C1_Init();
}
// SPI 2 Init
//static void MX_SPI2_Init(void);
void BSP_SPI2_Init( void )
{
MX_SPI2_Init();
}
void MX_I2C1_Init(void)
{
/* USER CODE BEGIN I2C1_Init 0 */
/* USER CODE END I2C1_Init 0 */
/* USER CODE BEGIN I2C1_Init 1 */
/* USER CODE END I2C1_Init 1 */
hi2c1.Instance = I2C1;
hi2c1.Init.Timing = 0x00C0EAFF;
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
{
Error_Handler();
}
/** Configure Analogue filter
*/
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
{
Error_Handler();
}
/** Configure Digital filter
*/
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN I2C1_Init 2 */
/* USER CODE END I2C1_Init 2 */
}
/**
* @brief SPI2 Initialization Function
* @param None
* @retval None
*/
void MX_SPI2_Init(void)
{
/* USER CODE BEGIN SPI2_Init 0 */
/* USER CODE END SPI2_Init 0 */
/* USER CODE BEGIN SPI2_Init 1 */
/* USER CODE END SPI2_Init 1 */
/* SPI2 parameter configuration*/
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 7;
hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI2_Init 2 */
/* USER CODE END SPI2_Init 2 */
}
Here is my native code where I use the I2C HAL read and write functions with the hi2c1 handle.
byte rdSensorReg8_8(uint8_t regID, uint8_t* regDat)
{
uint8_t i2cData[2];
i2cData[0] = regID;
HAL_I2C_Master_Transmit(&hi2c1, I2C_ID, i2cData, 1,1);
HAL_I2C_Master_Receive(&hi2c1, I2C_ID, &i2cData[1], 1,10);
return i2cData[1];
}
//I2C Array Write 8bit address, 8bit data
int wrSensorRegs8_8(const struct sensor_reg reglist[])
{
int err = 0;
uint8_t reg_addr = 0;
uint8_t reg_val = 0;
uint8_t i2cData[2];
const struct sensor_reg *next = reglist;
while ((reg_addr != 0xff) | (reg_val != 0xff))
{
reg_addr = next->reg;
reg_val = next->val;
i2cData[0]= reg_addr;
i2cData[1]= reg_val;
// err = wrSensorReg8_8(reg_addr, reg_val);
HAL_I2C_Master_Transmit(&hi2c1, I2C_ID, i2cData, 2,1);
// delay_us(400);
next++;
}
return err;
}
So the question is, how to use the I2C, use the CubeMx generated initialization or the the existing initialization and handler?
Thanks,
MMD