Raspberry PI, raw, read case value in C

Can someone please show me an example of how to read values โ€‹โ€‹from raspberry registers? I need to check the byte in AUX_MU_LSR_REG (0x7E21 5054), but I do not know how to do this without using any additional libraries. I tried: (here I am changing the oryginal message)

************************** * 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 and writing to maped memmory MAP_SHARED, //Shares with other processes mem_fd, //File to 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 the code Now I really donโ€™t remember how I show 0, but in the above code I get a pointer conflict.

What does uart point to? Theoretically, it should display values, but after a few weeks I can not get it to work.

I hope you can help me somehow

+4
source share
1 answer

I successfully compiled an example here and was able to read and write digital values โ€‹โ€‹from GPIO pins with a slight modification to this code.

You are essentially moving in the right direction: mmap() range specified in the data table for your specific GPIO, SPI, or any register you need, then read and write from this address. This is the basis of all GPIO programming on RPi.

There are some special bit fields that you should pay attention to, but, as I mentioned, all of them are in the data tables for Pi on the elinux.org page.

note : up to mmap() system registers that you must run as superuser.

+2
source

Source: https://habr.com/ru/post/1479773/


All Articles