Modified master architecture.

Adjusted behavior to the new slave device architecture. The program quits as soon as it's done talking to the slave.
master
Davide Bongiovanni 10 years ago
parent b8fb5ef4ab
commit 1a1287f089

@ -21,41 +21,30 @@
#include <wiringPi.h>
#include <wiringPiI2C.h>
int main (int argc, char *argv[])
{
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);
}
}
}
return 0;
#define I2C_ADDR 0x20
uint8_t solve_challenge(uint8_t arg) {
return (arg >> 3) ^ (arg << 3);
}
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;
}

Loading…
Cancel
Save