2

Did the following steps just to test if my temperature sensor HTU2X is working or not. Selected my board (Nucleo-64 STM32F411RE) from STM32CubeIDE then enabled I2C1 which in turn enabled pins PB6 (as the SCL) and PB7 (as the SDA) as in the screenshot below, then saved the project. enter image description here

Then added code below:

I2C_HandleTypeDef hi2c1;
UART_HandleTypeDef huart2; 
void I2C1_Scan()
        {
            char msg[32];
            for (uint8_t addr7 = 0; addr7 <= 127; addr7++)
            {
                uint16_t addr8 = addr7 << 1; // what HAL expects
                if (HAL_I2C_IsDeviceReady(&hi2c1, addr8, 2, 1000) == HAL_OK)
                {
                    // print in both 7-bit and 8-bit forms to avoid confusion
                    snprintf(msg, sizeof(msg), "Found: 0x%02X (7b), 0x%02X (8b)\r\n", addr7, addr8);
                    HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
                }
            }
            HAL_UART_Transmit(&huart2, (uint8_t*)"No match!\r\n", 12, HAL_MAX_DELAY);
        }
        
       // ...
int main() {
     // ...
        HAL_Delay(100); // give power and peripherals time to settle
        I2C1_Scan();
        while(1) {
        //...

Below is also the wiring: enter image description here

I get "No match!". Any idea where the problem is and how to fix it?

1 Answer 1

1

You don't have any pull-up resistors on SDA and SCL lines. Look at the PCB carefully, the 3 jumper pads need to be solder together to use the two on-board pull up resistors.

enter image description here

Edit: It is unclear from your post photo where exactly the purple line (SCL) connected to, please make sure it is indeed connect to PB6, which should be the D10 on the CN5 (Arduino Connector) or pin 17 on CN10 (Morpho Connector). pin 18 of CN10 is NC. enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

I've got two external 3KΩ resistors. Can't they do what the internal resistors do well enough? If they can, I may be able to use them instead of soldering those three pads.
The purple wire is connected to pin 17 (i.e., the 9th from top). The reduced 30KHz I2C clock speed didn't work either. So I will buy 10KΩ resistors and try again. If still "No match!" then I will remove the external resistors and solder those three pin pads.
Basically any resistor between 2-10k should work. Your code looks okay, so maybe if you have another I2C sensor (any I2C device), you should test it to see if you could the response, that at least rule out the code and the connection. As you could have a faulty HTU2X.
Soldered the pin pads, selected PB8 and PB9 for I2C1 on the IDE this time and connected the pins this way imgur.com/a/qRBFoRE. Result: mostly "No match!" and precious few times "Found: 0x00 (7b), 0x00 (8b)" (which is unclear when). Don't you think the sensor is damaged?
Soldered the 4-leg pins into those 4 holes and tested it again and now get Found: 0x40 (7b), 0x80 (8b). The issue this way was solved.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.