2024-06-23 08:43 AM - last edited on 2024-07-30 06:31 AM by Andrew Neil
Hello,
I am coming to you because I have a rather difficult issue to identify.
I have a screen mounted on I2C that originally communicates with an Arduino board via its address 0x3C. I have verified that I can communicate with this address using my Nucleo 64 F401RE board.
However, when I look at the frames, I encounter information that doesn't match up. Worse, when I look at what HAL returns, I get a rather strange error that I would like to submit to you.
In order:
Here is a piece of code in C:
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "i2c.h"
#include "usart.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stdio.h" // sprintf()
#include "stdbool.h" // boolean
/* USER CODE END Includes */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define DELAY_MAN 500
#define ADDRESSE_ECRAN 0x3C
#define NB_COLONNES 16
#define NB_LINES 2
/* USER CODE END PD */
/* 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 */
void RW1063_send_command(uint8_t command);
void RW1063_show_cursor();
void RW1063_hide_cursor();
void RW1063_blink_cursor();
void RW1063_no_blink_cursor();
/* 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_USART2_UART_Init();
/* USER CODE BEGIN 2 */
RW1063_send_command(0x38); // 8-bit mode, 2 lines, 5x8 characters
HAL_Delay(1);
RW1063_send_command(0x0C); // Turn on the screen, disable cursor and blinking
HAL_Delay(1);
RW1063_send_command(0x01); // Clear the screen
HAL_Delay(10);
RW1063_send_command(0x06); // Move the cursor to the right after each character
HAL_Delay(1);
RW1063_show_cursor();
HAL_Delay(500);
RW1063_hide_cursor();
HAL_Delay(500);
RW1063_show_cursor();
RW1063_blink_cursor();
HAL_Delay(2000);
RW1063_no_blink_cursor();
HAL_Delay(500);
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
}
}
void RW1063_send_command(uint8_t command) {
HAL_StatusTypeDef res;
uint16_t size_buff = 2;
uint8_t tbl_command[size_buff];
tbl_command[0] = 0x00;
tbl_command[1] = command;
res = HAL_I2C_Master_Transmit(&hi2c1, ADDRESSE_ECRAN << 1, tbl_command, size_buff, HAL_MAX_DELAY);
if(res != HAL_OK) {
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
while(1);
}
}
void RW1063_show_cursor() {
RW1063_send_command(0x0E);
}
void RW1063_hide_cursor() {
RW1063_send_command(0x0C);
}
void RW1063_blink_cursor() {
RW1063_send_command(0x0F);
}
void RW1063_no_blink_cursor() {
RW1063_send_command(0x0C);
}
I am also attaching images to illustrate the frames and errors encountered.
Thank you in advance for your help!
2024-06-24 11:19 AM
@Geeks wrote:it compiles without error in me, so even the compiler agrees and does not see any error.
The compiler can only tell you that there were no C syntax errors - it has no clue whether that code will actually function correctly!
2024-06-24 11:38 AM
Yes, I know, like all compilers.
But in general, that of ST is still verbose. And there, nothing...
However, randomly the variable res does not remain null!
2024-06-24 11:51 AM
Did you buy the 5V logic one, or the 3V variant? The former being "Arduino" compatible in the ATMEGA sense, but less so in the STM32 sense.
Still not seeing any wiring diagram. When things don't make sense you need to zoom out and look at the bigger picture.
PB6/PB7 should be FT (5V Tolerant)
You used 2K2 pull-ups?
Is it powered properly, is it grounded properly?
Contrast Logic-Analyzer plots between working / non-working situations, ideally using the GPIO to trigger / associate the capture and failing, and seeing if you can circle the specific issue the STM32 is flagging.
2024-06-24 11:54 AM
The resistors are with the level shifter. And it works perfectly on other mics. 33 to 5V and tolerates 5V to 5V.
We can isolate this problem.