FPGARelated.com
Forums

problem in driving I2C bus through memory-mapped register

Started by Unknown April 1, 2005
Hi,

        I have an fpga which is accessed from ARM as a
memory-mapped device.

A register in fpga is used to drive a I2C bus connected to
a device . Two bits in the register represent clock and
data lines of the bus.

When I try to write into this register from ARM software as
shown below, write is not happening. ARM is running at 48 Mhz.

int* reg = 0x44400030;
*reg = 0x3;

The above code is not able to modify the register.

But when I write using Lauterbach trace32 command as shown below, it
works.

data.set SD:0x44400030 %LE %LONG 0x3

What could be the reason ?

    Please advise.
                thanks
                      shankar

On 1 Apr 2005 04:25:56 -0800, <shankar.vk@gmail.com> wrote:

> int* reg = 0x44400030; > *reg = 0x3; > [...] > > What could be the reason ?
Possibly, missed "volatile" qualifier. Vadim Borshchev
Try this:

int* reg = (int*)0x44400030;
*reg = 0x3;

Regis.

<shankar.vk@gmail.com> wrote in message 
news:1112358355.997835.104340@z14g2000cwz.googlegroups.com...
> > Hi, > > I have an fpga which is accessed from ARM as a > memory-mapped device. > > A register in fpga is used to drive a I2C bus connected to > a device . Two bits in the register represent clock and > data lines of the bus. > > When I try to write into this register from ARM software as > shown below, write is not happening. ARM is running at 48 Mhz. > > int* reg = 0x44400030; > *reg = 0x3; > > The above code is not able to modify the register. > > But when I write using Lauterbach trace32 command as shown below, it > works. > > data.set SD:0x44400030 %LE %LONG 0x3 > > What could be the reason ? > > Please advise. > thanks > shankar >
Or this:

int* reg = (int*)0x44400030;
*reg = 0x3L;

 Regis (regis@dacafe.com)

"RS" <regis@dacafe.com> wrote in message 
news:CVd3e.43674$AN1.42984@fed1read03...
> Try this: > > int* reg = (int*)0x44400030; > *reg = 0x3; > > Regis. > > <shankar.vk@gmail.com> wrote in message > news:1112358355.997835.104340@z14g2000cwz.googlegroups.com... >> >> Hi, >> >> I have an fpga which is accessed from ARM as a >> memory-mapped device. >> >> A register in fpga is used to drive a I2C bus connected to >> a device . Two bits in the register represent clock and >> data lines of the bus. >> >> When I try to write into this register from ARM software as >> shown below, write is not happening. ARM is running at 48 Mhz. >> >> int* reg = 0x44400030; >> *reg = 0x3; >> >> The above code is not able to modify the register. >> >> But when I write using Lauterbach trace32 command as shown below, it >> works. >> >> data.set SD:0x44400030 %LE %LONG 0x3 >> >> What could be the reason ? >> >> Please advise. >> thanks >> shankar >> > >
<shankar.vk@gmail.com> wrote in message
news:1112358355.997835.104340@z14g2000cwz.googlegroups.com...

> int* reg = 0x44400030; > *reg = 0x3; > > The above code is not able to modify the register.
Have you previously written the same value to that location ? If so, it's possible that your compiler spots the duplication and doesn't do it a second time (unless you write something else in between). This is because "int" refers to a "variable" and not a memory location, per se. The difference is that writing to a memory location can have a side effect. This is what you want, so you may need to stick a "volatile" qualifier in, to make sure the compiler really does do a write. Richard [in PE12]
shankar.vk@gmail.com wrote:

> When I try to write into this register from ARM software as > shown below, write is not happening. ARM is running at 48 Mhz. > > int* reg = 0x44400030; > *reg = 0x3; > > The above code is not able to modify the register.
I recommend that you look at the compiler output, either through an assembly listing or, better yet, through the disassembly output of a debugger. See what code is being generated. Compare that to what you know works. This is a powerful technique that all programmers, but especially embedded systems programmers and systems programmers can benefit from. It might have something to do with memory mapping or the width of the write, but those are just guesses. Thad
Thanks to all who replied.

I forgot to add that the same C code works when executed from an ARM
core which
is part of the same fpga which contains the I2C register

So the code is perfect.

We analysed the memory access signals such as chip select,  write
enable, wait etc
using a TLA .   They look OK.

The wait signal comes as an input to  the memory controller peripheral
of ARM  from the fpga.

               thanks

Let me add that  there are  other  memory mapped registers on the fpga
.
I have a problem only accessing the I2C related register.

In terms of execution flow, what is the difference between  memory
access through :
a) Trace32 JTAG debugger
and 
b) code running on arm      ?

As I  said, the memory access works through jtag debugger  Trace32.

What is the difference in execution flow of   memory access through
debugger
command and  software instruction ?  This is the key  to solve this
problem.

shankar.vk@gmail.com wrote in
news:1113222190.466570.106750@l41g2000cwc.googlegroups.com: 

> As I said, the memory access works through jtag debugger > Trace32. > > What is the difference in execution flow of memory access > through debugger > command and software instruction ? This is the key to > solve this problem.
stepping the code will cause a drain of the write buffer on every instruction to syncronize 'memory', Your first post has expired here - so I don't know what core you are using. Is the write buffer coelessing?