Read/write a single bit (MCP23018)


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2006
    Location
    Surrey, BC, Canada
    Posts
    31

    Red face Read/write a single bit (MCP23018)


    Hello everybody.
    I’m stack in a simple problem. My application required communication with I/O expander MCP23018.
    I made it work except one thing. I need to read single bit and ignore all others. I need also to write a single bit and leave unchanged others. As command looks like this
    i2cwrite sda,scl,CTRL_EE_W,[GPIOB,%00000011]
    so, how can I change, for example 3 bit, and leave all other bits unchanged ( value of other bits unknown and might change)
    I need also read a single bit and ignore value of others.
    i2cread sda,scl,CTRL_EE_R,[IO_dat]
    Any input welcome!
    Vladimir

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Read/write a single bit (MCP23018)

    Bitwise operation & masks

    assuming VarA = %11110000

    If i want to set a single bit, say Bit0, I can do it like
    VarA.0=1

    OR doing it with mask
    VarA = VarA | %00000001

    If you want to clear a bit, says bit 7, then you use
    VarA.7=0

    OR

    VarA = VarA & %01111111

    If I want to READ a single bit, say bit 2, then, I can use
    AnotherVar = VarA.2
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jul 2006
    Location
    Surrey, BC, Canada
    Posts
    31


    Did you find this post helpful? Yes | No

    Default Re: Read/write a single bit (MCP23018)

    Thank you, Steve.
    It is all I need!!!

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Read/write a single bit (MCP23018)

    No problem dear Canadian brother
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts