ARM Linux Examples for GPIO, I2C etc.

hello,

I am new at ARM-Linux. I tried successfully “hello world” example at one

olimex board (SAM9-L9260) and now I want to learn more about ARM

programming under Linux. Do someone have example code for using of I2C

at arm linux? Also I am searching for simple GPIO linux examples e.g. to

let blink one LED on some custom defined IO Pin.

thanks for help

check this, try to do sthg similar , access gpio fro user space is a good start. the register are for E9302, just check a particular datasheet and change them to be used with any uC.

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#define GPIO_BASE 0x80840000
/* GPIO memory mapped registers */
volatile unsigned int *PEDR;
volatile unsigned int *PEDDR;
	
int main (void)
	{	
  	//long delay=128000, delay2=100;
  	unsigned char *gpio;
  	int fd;
  	fd = open("/dev/mem", O_RDWR);
  	if (fd < 0) 
  		{
   	perror("Failed to open /dev/mem");
   	return fd;
  		}
  	gpio = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_BASE);

  	PEDR = (unsigned int *)(gpio + 0x20);
  	PEDDR = (unsigned int *)(gpio + 0x24);
	
	*PEDDR = 0xff;//set output
	*PEDR = 0x02;// turn ON Red LED (port E1)
		
  	return 0;
	}

Raed