Estou tentando usar um Attiny84A como escravo numa rede I2C, quero usar ele como um ADC via I2C.
A principio estou usando a biblioteca USI TWI Slave driver,
inclui a configuração do Attiny84A
#if defined( __AVR_ATtiny84__ )
# define DDR_USI DDRA //DDRB
# define PORT_USI PORTA //PORTB
# define PIN_USI PINA //PINB
# define PORT_USI_SDA PA6 //PB0
# define PORT_USI_SCL PA4 //PB2
# define PIN_USI_SDA PINA6 //PINB0
# define PIN_USI_SCL PINA4 //PINB2
# define USI_START_COND_INT USISIF //was USICIF jjg
# define USI_START_VECTOR USI_START_vect
# define USI_OVERFLOW_VECTOR USI_OVF_vect
#endif
No main.c está esse código
- Código: Selecionar todos
// Own TWI slave address
// Endereço do escravo TWI próprio
// slaveAddress = 0x10;
slaveAddress = 0x92;
usiTwiSlaveInit(slaveAddress);
// Set global interrupt enable
sei();
// This loop runs forever. If the TWI Transceiver is busy the execution will just continue doing other operations.
// Este loop é executado para sempre. Se o TWI Transceiver estiver ocupado, a execução continuará fazendo outras operações.
for(;;)
{
wdt_reset();
if(usiTwiDataInReceiveBuffer())
{
Set_Down_Bit( PORTB, Saida_A0 );
temp = usiTwiReceiveByte();
switch (temp)
{
case 0x92: Set_Down_Bit( PORTB, Saida_A1 ); break;
case 0x40: Set_Down_Bit( PORTB, Saida_A2 ); break;
usiTwiTransmitByte(distance);
}
// usiTwiTransmitByte(distance);
}
// Do something else while waiting for the TWI transceiver to complete.
// Faça outra coisa enquanto espera a conclusão do transceptor TWI.
asm volatile ("NOP" ::);
}
return 0;
}
Porém não está nem acionando o led1 que indica o recebimento de dados.
Alguém pode ajudar ?