You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
664 B
49 lines
664 B
/* I2C Echo Example */
|
|
#include "../I2CSlave/I2CSlave.h"
|
|
|
|
#define I2C_ADDR 0x20
|
|
|
|
volatile uint8_t data;
|
|
volatile uint8_t final;
|
|
void I2C_received(uint8_t received_data)
|
|
{
|
|
data = received_data;
|
|
}
|
|
|
|
void I2C_requested()
|
|
{
|
|
I2C_transmitByte(data);
|
|
}
|
|
void I2C_challenge() {
|
|
I2C_transmitByte(data*3);
|
|
}
|
|
|
|
void setup()
|
|
{
|
|
// set received/requested callbacks
|
|
I2C_setCallbacks(I2C_received, I2C_requested);
|
|
|
|
// init I2C
|
|
I2C_init(I2C_ADDR);
|
|
// init output gpio
|
|
DDRB = 0b00000001;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
setup();
|
|
|
|
// Main program loop
|
|
while(1) {
|
|
if(data != 4) {
|
|
I2C_challenge();
|
|
}
|
|
else {
|
|
//PORTB |= 1<<1;
|
|
data = 2;
|
|
I2C_requested();
|
|
|
|
}
|
|
}
|
|
}
|