V
V
Vadimm10012018-09-13 18:55:28
Electronics
Vadimm1001, 2018-09-13 18:55:28

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);

Mk is tuned to a clock frequency of 1 MHz from the internal generator. Powered the microcontroller on the one hand, that is, connected only to VCC and GND. On the oscilloscope, the SDA and SCL line rises for about a second and there is nothing further. Everything works in Proteus. The chip says PCF8574T, not PCF8574 or PCF8574A.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vanyamba-electronics, 2018-09-13
@vanyamba-electronics

Well, here is an example of working with TWI .

W
wibsea, 2018-09-14
@wibsea

What are the levels on A0,A1,A2?

A
Alex Other planet, 2018-10-12
@BadElectrician

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 question

Ask a Question

731 491 924 answers to any question