UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for
Search instead for
Did you mean:
Explorer
3,116 Views
Registered: ‎10-25-2012

## How to program C to assign the value in a specific bit of a address in IIC？

Jump to solution

To configure a IIC slave device, in a address, only a specific bit needs to be assigned,e.g.:

0x41[6] = 0b0

My question is: In SDK, how to program C code to assign the value in this specific bit without changing other bits？

Thanks very much.

1 Solution

Accepted Solutions
Highlighted
Explorer
3,947 Views
Registered: ‎05-12-2011

## Re: How to program C to assign the value in a specific bit of a address in IIC？

Jump to solution

Assuming you want to access memory as a 32-bit word and clear bit 6, something like

u32 *ptr = (u32 *)0x41;    // Pointer set to address of word

u32 val;                            // Variable to hold word while we modify it

val = *ptr;                            // Load the word

val = val & ~0x00000040;  // Clear bit 6

*ptr = val;                           // Store the modified word

The '&' operator is a bit-wise logical AND, '~' is bit-wise complement (invert).  So val = val AND 0xFFFFFFBF is what happens to clear the bit.

Cheers,

-Doug

2 Replies
Highlighted
Explorer
3,948 Views
Registered: ‎05-12-2011

## Re: How to program C to assign the value in a specific bit of a address in IIC？

Jump to solution

Assuming you want to access memory as a 32-bit word and clear bit 6, something like

u32 *ptr = (u32 *)0x41;    // Pointer set to address of word

u32 val;                            // Variable to hold word while we modify it

val = *ptr;                            // Load the word

val = val & ~0x00000040;  // Clear bit 6

*ptr = val;                           // Store the modified word

The '&' operator is a bit-wise logical AND, '~' is bit-wise complement (invert).  So val = val AND 0xFFFFFFBF is what happens to clear the bit.

Cheers,

-Doug

Explorer
3,100 Views
Registered: ‎10-25-2012

## Re: How to program C to assign the value in a specific bit of a address in IIC？

Jump to solution
Thanks very much.