Proposed correction to bcm2835_i2c_write()

18 views
Skip to first unread message

hen...@open-source.se

unread,
Oct 26, 2025, 11:20:25 AM (3 days ago) Oct 26
to bcm2835
Hello again!

I propose the following correction in the function bcm2835_i2c_write():

--- bcm2835-1.75/src/bcm2835.c  2024-02-12 03:27:45.000000000 +0100
+++ ../bcm2835/bcm2835-1.75/src/bcm2835.c       2025-10-26 00:20:24.439457781 +0200
@@ -1384,7 +1384,8 @@
        reason = BCM2835_I2C_REASON_ERROR_DATA;
     }

-    bcm2835_peri_set_bits(control, BCM2835_BSC_S_DONE , BCM2835_BSC_S_DONE);
+    bcm2835_peri_set_bits(status, BCM2835_BSC_S_DONE , BCM2835_BSC_S_DONE);
+    bcm2835_peri_write(control, 0); // reset BSC control register after transfer


     return reason;

 }

It seems wrong to set the BSC control register with bits for the status register.
The same call is repeated at the end of bcm2835_i2c_read_register_rs() and bcm2835_i2c_write_read_rs() so these may also need to be corrected.



Mike McCauley

unread,
Oct 28, 2025, 5:50:08 PM (22 hours ago) Oct 28
to bcm2835, hen...@open-source.se

Hello Henrik,


thanks for your report.


You say "seems wrong" but have you tested wether your change is correct and works correctly?


According to the documentation for the Status Done bit:


DONE Transfer Done
0 = Transfer not completed. 1 = Transfer
complete. Cleared by writing 1 to the field.


Cheers.

--

Mike McCauley           VK4AMM                   mi...@airspayce.com

Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia  

http://www.airspayce.com                                 5R3MRFM2+X6

Phone +61 7 5598-7474


hen...@open-source.se

unread,
7:09 AM (9 hours ago) 7:09 AM
to bcm2835
Hello Mike,

Yes, I have tested the correction (working on a project with a BME280 sensor and an ssd1306 OLED display connected to I2C).
My point was that the existing code writes BCM BSC S (Status) register bits (BCM2835_BSC_S_DONE) to the BSC C (Control)  register.

bcm2835_peri_set_bits(control, BCM2835_BSC_S_DONE , BCM2835_BSC_S_DONE);

The BCM2835_BSC_S_DONE bit will (probably?) have no effect on the Control register since it is marked as "Reserved".
And thanks for the bcm2835 library, by the way!

Kind regards,
/Henrik




Reply all
Reply to author
Forward
0 new messages