Hardware Reference
In-Depth Information
89 msgset.msgs = iomsgs;
90 msgset.nmsgs = 1;
91
92 rc = ioctl(i2c_fd,I2C_RDWR,&msgset);
93 assert(rc == 1);
94 }
95
96 /
97
Read nunchuk data :
98
/
99 static int
100 nunchuk_read(nunchuk_t
data) {
101 struct i2c_rdwr_ioctl_data msgset;
102 struct i2c_msg iomsgs[1];
103 char zero[1] = {0x00}; /
Written byte
/
104 unsigned t;
105 int rc;
106
107 timed_wait(0,15000,0);
108
109 /
110
Write the nunchuk register address of 0x00:
111
/
112 iomsgs[0].addr = 0x52; /
Nunchuk address
/
113 iomsgs[0].flags = 0; /
Write
/
114 iomsgs[0].buf = zero; /
Sending buf
/
115 iomsgs[0].len = 1; /
1 byte
/
116
117 msgset.msgs = iomsgs;
118 msgset.nmsgs = 1;
119
120 rc = ioctl(i2c_fd,I2C_RDWR,&msgset);
121 if ( rc < 0 )
122 return −1; /
I /O error
/
123
124 timed_wait(0,200,0); /
Zzzz, nunchuk needs time
/
125
126 /
127
Read 6 bytes starting at 0x00:
128
/
129 iomsgs[0].addr = 0x52; /
Nunchuk address
/
130 iomsgs[0].flags = I2C_M_RD; /
Read
/
131 iomsgs[0].buf = (char
)data−>raw; /
Receive raw bytes here
/
132 iomsgs[0].len = 6; /
6 bytes
/
133
134 msgset.msgs = iomsgs;
135 msgset.nmsgs = 1;
136
Search WWH ::




Custom Search