Reputation: 11
bcm2835 init works fine, as does all the GPIO & bcm2835_delay and the like.
RPi4 & Pi400, Raspbian "Bullseye", bcm2835 1.71, Libcap installed, added the program name etc
And I've compiled with Geany gcc -Wall -o "%e" "%f" -pthread $(pkg-config gtk+-3.0 --cflags --libs) -export-dynamic -l bcm2835 -l png -DBCM2835_HAVE_LIBCAP
Here's code:
// bcm_timer.c
//
// Example program for bcm2835 library system time
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <bcm2835.h>
uint64_t now = 0;
uint64_t then = 0;
uint rescode = 0;
int main(int argc, char **argv)
{
// Init GPIO
if ( ! bcm2835_init() )
{
printf("Fail 0x%X ", errno);
return -1;
}
then = bcm2835_st_read();
bcm2835_delay(500);
now = bcm2835_st_read();
printf("Then = 0x%lluX, Now = 0x%lluX \n", then, now) ;
bcm2835_close();
return 0;
}
Here's output:
xxx@raspberrypi:~/Develop/c/test $ ./bcm_timer
Then = 0x0X, Now = 0x0X
Upvotes: 1
Views: 175
Reputation: 11
If you (or someone else) is still looking for the answer to this question, you need to run your code with sudo for bcm2835_st_read to work.
In my experiments, some things in the BME library require sudo (ran into this issue with i2c and the system timer), and some don't (gpio). Yes, it's annoying.
Hope this helps you or someone. -mg
Upvotes: 1