Modified master architecture.
Adjusted behavior to the new slave device architecture. The program quits as soon as it's done talking to the slave.
This commit is contained in:
+24
-35
@@ -21,41 +21,30 @@
|
|||||||
#include <wiringPi.h>
|
#include <wiringPi.h>
|
||||||
#include <wiringPiI2C.h>
|
#include <wiringPiI2C.h>
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
#define I2C_ADDR 0x20
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
int data;
|
|
||||||
int send=1;
|
|
||||||
wiringPiSetup () ;
|
|
||||||
fd=wiringPiI2CSetup (0x20) ; /*Use i2cdetect command to find your respective device address*/
|
|
||||||
if(fd==-1)
|
|
||||||
{
|
|
||||||
printf("Can't setup the I2C device\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
delay(1);
|
|
||||||
while(1) {
|
|
||||||
wiringPiI2CWrite(fd, send);
|
|
||||||
data=wiringPiI2CRead(fd);
|
|
||||||
printf(" Received data=%d\n", data);
|
|
||||||
if(data==-1)
|
|
||||||
{
|
|
||||||
printf("No data\n");
|
|
||||||
//return -1;
|
|
||||||
}
|
|
||||||
else if(data == 17) {
|
|
||||||
printf("Exit code received \n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if(data != 0) {
|
|
||||||
printf("Sending response %d\n", data+3 );
|
|
||||||
wiringPiI2CWrite(fd, data+3);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
uint8_t solve_challenge(uint8_t arg) {
|
||||||
}
|
return (arg >> 3) ^ (arg << 3);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
int fd; // Linux filehandle to the i2c device
|
||||||
|
uint8_t challenge;
|
||||||
|
uint8_t response;
|
||||||
|
wiringPiSetup();
|
||||||
|
|
||||||
|
fd = wiringPiI2CSetup(I2C_ADDR); // Initialize the i2c protocol with the address
|
||||||
|
if (fd == -1) { // Failed to contact device
|
||||||
|
printf("Can't setup the I2C device\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(1);
|
||||||
|
|
||||||
|
challenge = wiringPiI2CRead(fd);
|
||||||
|
response = solve_challenge(challenge);
|
||||||
|
wiringPiI2CWrite(response);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user