LCD Controller Register not readable/ writeable: Gets Bus error

Dear All,

I am trying to access the LCD controller of the AM335X on the Beagle Bone Black. I use a Linux debian.

Below is the code…

#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <string.h>
#include<stdint.h>
#include <linux/types.h>
#include <signal.h>
#include <sys/mman.h>

#define LCD_BASE 0x4830E000
#define LCD_TOP 0x4830F000
#define LCD_SIZE (LCD_TOP - LCD_BASE)
#define PID 0

#define GPIO1_START_ADDR 0x4804C000
#define GPIO1_END_ADDR 0x4804E000
#define GPIO1_SIZE (GPIO1_END_ADDR - GPIO1_START_ADDR)
#define GPIO_SETDATAOUT 0x194
#define GPIO_CLEARDATAOUT 0x190
#define USR3 (1<<24)

void main()
{

// LCD Code Area…
int state;

int mem, loop_i;

volatile void* lcd_mem_addr;

volatile unsigned int *reg_data;

volatile unsigned int reg_value;

if ((mem = open ("/dev/mem", O_RDWR)) < 0)
{

printf(“Cannot open /dev/mem\n”);

return 1;
}

lcd_mem_addr = mmap(0, LCD_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem, LCD_BASE);

printf("\n Lets read LCD Controller PID register first");

reg_data = lcd_mem_addr + PID;// lcd_register_offset[loop_i]);

printf("\n Address is %x ", (lcd_mem_addr + PID));

sleep(1);

reg_value = *reg_data;

printf("\n Set Value in LCD from reg = %x", reg_value);

close(mem);

munmap(lcd_mem_addr, 0x0100);

//…LCD Code Ends

//…GPIO Code starts

volatile void *gpio_addr;
volatile unsigned int *gpio_setdataout_addr;
volatile unsigned int *gpio_cleardataout_addr;
int fd = open("/dev/mem", O_RDWR);
gpio_addr = mmap(0, GPIO1_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO1_START_ADDR);

gpio_setdataout_addr = gpio_addr + GPIO_SETDATAOUT;
gpio_cleardataout_addr = gpio_addr + GPIO_CLEARDATAOUT;

while(1)
{

sleep(2);

*gpio_setdataout_addr = USR3;

reg_value = *gpio_setdataout_addr;

printf("\n Set Value from reg = %x", reg_value);

sleep(2);

*gpio_cleardataout_addr = USR3;

reg_value = *gpio_setdataout_addr;

printf("\n Clear Value from reg = %x", reg_value);

}//while

}//main


The output of the above code when it is run is

root@beaglebone:/home/mYprojects/LCD/userspace# ./LCD_3.o

Lets read LCD Controller PID register first
Bus error
root@beaglebone:/home/mYprojects/LCD/userspace#

If I comment the below line that comes in the LCD code section, the program executes correctly and I can see the LED Flashing.
reg_value = *reg_data

I am not sure why I am not able to access the LCD registers through mmap() but I am able to access the GPIO registers through mmap().

Could someone please point out what is going wrong here?

Thanks & Regards
Anu