Answer the question
In order to leave comments, you need to log in
Unable to connect to the PCF8574T expander?
Here is the code:
#include <avr/io.h>
#define F_CPU 1000000UL
#include <util/delay.h>
#include <math.h>
#include "lcd_func.h"
unsigned char twi_start(void)
{
TWCR|=(1<<TWINT)|(1<<TWEN)|(1<<TWSTA);
while(!(TWCR & (1<<TWINT)));
return TWSR;
}
unsigned char twi_write(unsigned char data)
{
TWDR=data;
TWCR|=(1<<TWINT)|(1<<TWEN);
while(!(TWCR & (1<<TWINT)));
return TWSR;
}
void twi_stop(void)
{
TWCR|=(1<<TWINT)|(1<<TWEN)|(1<<TWSTO);
}
int main (void)
{
_delay_ms(1000);
lcd_init();
TWBR=2;
lcd_integer(twi_start()); // Выводит 0x08
lcd_integer(twi_write(0b01000000)); /*Это адрес с битом записи, выводит 0х20, то есть ведомый
ответил NACK */
lcd_integer(twi_write(0x01)); /*Это просто значение которое хочу записать в порт PCF8574T выводит 0х10 то есть поступил повторный старт.*/
while(1);
Answer the question
In order to leave comments, you need to log in
Well, here is an example of working with TWI .
Look at the datasheet carefully.
Expanders at this frequency do not work. 100 kHz is about their range. The datasheets give examples of how to adjust the frequency of the lines. Plus, the capacitance of the lines greatly affects the data transmission lines, so this is not only a software issue, but also a hardware one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question