Raspberry PI, raw reading a register value in C -


can please show me example on how read values raspberry pi registers? need check byte in aux_mu_lsr_reg (0x7e21 5054) don't know how without usage of additional libraries. tried to: (here modify oryginal post)

**************************start of code

#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys/mman.h> #include <unistd.h> #include <errno.h>    #define bcm2708     0x20000000 #define uart_base   (bcm2708+0x215000) #define page_size   (4*1024) #define block_size  (4*1024)    int mem_fd;                  void *uart_map;                  volatile unsigned *uart;                 int main() {  printf("start\n");  if((mem_fd=open("/dev/mem",o_rdwr|o_sync))<0) { printf("can't open /dev/mem \n"); exit(-1); } else printf("stream_file open ok \n");  if((uart_map=malloc(block_size))==0) printf("malloc fail\n"); else printf("gpio_mallocation ok %d \n", (int)uart_map );   uart_map=mmap   (null,          //any address in our space block_size,         //map length prot_read|prot_write,   //enable reading , writing maped memmory map_shared,     //shares other processes mem_fd,         //file map uart_base       //offset touart peripheral );  if(uart_map==map_failed) { printf("mmap error %d", (int)uart_map); exit(-1); } else printf("gpio mapping ok \n"); uart=(volatile unsigned* )uart_map; int i;  for(i=0;i<32;i++) { printf("adress:%x ",uart+i); printf("value:%x\n",*(uart+i)); }      printf("stop\n"); return 0; } 

` ***********************end of code don't remember how display 0 in above code pointer conflict.

what uart pointing to? in theory should display values after few weeks can't make running.

hope can me somehow

i've compiled example here , been able read , write digital values gpio pins little modification code.

you're heading in right direction: mmap() range specified in datasheet particular gpio, spi or whichever register need, , read , write address. that's basis of gpio programming on rpi.

there special bitfields should pay attention to, mentioned, these in datasheets pi @ elinux.org

note: mmap() system registers need running superuser.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -