# Reading and writing registers

**URL:** <https://www.ruby-forum.com/t/reading-and-writing-registers/74812>\
**Category:** GNU Radio\
**Created:** [November 7, 2006, 10:57am UTC](https://www.ruby-forum.com/t/reading-and-writing-registers/74812 "2006-11-07T10:57:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![seph\_004](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@seph\_004](https://www.ruby-forum.com/u/seph_004)\
**Post date:** [November 7, 2006, 10:57am UTC](https://www.ruby-forum.com/t/reading-and-writing-registers/74812/1 "2006-11-07T10:57:49Z")

</div>

Hi

I am having some trouble trying to get register writing and reading from  
the C++ level to work. I’ve created two methods:

for writing

static bool  
write\_a\_reg (usrp\_basic \*u, int address, int amount)  
{  
bool isit = u-\>\_write\_fpga\_reg (address, amount);

return isit;  
}

for reading

int  
read\_a\_reg (usrp\_basic \*u, int address)  
{  
int val = u-\>\_read\_fpga\_reg (address);

return val;  
}

When I use the write method:

bool fine2 = write\_a\_reg (urx, 78, 60);

The returned boolean indicates that the write was successful. If I try  
to read the same register though:

int value = read\_a\_reg (urx, 78);

it always returns zero no matter what I put in. The urx is the handle of  
a usrp\_standard\_rx object, and if I’m not mistaken, register number 78  
(`FR\_USER\_14) shoul be free to use. What am I doing wrong?

Regards

Lance

---

<div class="post-metadata">

**Author:** ![seph\_004](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@seph\_004](https://www.ruby-forum.com/u/seph_004)\
**Post date:** [November 7, 2006, 10:59am UTC](https://www.ruby-forum.com/t/reading-and-writing-registers/74812/2 "2006-11-07T10:59:37Z")

</div>

On Fri, Nov 03, 2006 at 02:43:46AM -0800, seph 004 wrote:

> Hi

> return isit;  
> }  
> register number 78 (`FR\_USER\_14) shoul be free to use. What am I  
> doing wrong?

> Regards  
> Lance

Assuming that all registers are readable, or that they  
are in the same address space as the writable registers would be a  
mistake.

Try reading from registers 1, 2 or 3. See  
usrp/firmware/include/fpga\_regs\_standard.h, down toward the bottom.

Please also note that writing random values into random registers can  
lead to permanent damage. FR\_USER\_0 through FR\_USER\_15 are safe to  
write with the .rbf’s that we distribute. We don’t pay any attention  
to them.

Eric
