AnsweredAssumed Answered

12864B I2C LCD I will ask. (STM32F429)

Question asked by Study Yahoo on Nov 29, 2017
Latest reply on Dec 11, 2017 by shane mattner
Hi everyone
That link page 12864 I2C LCD
(http://zhongbest.com/2017/04/05/i2c-lcd12864%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%85%BC%E5%AE%B9arduino/)

 

I have a question. (STM32F207)
12864 to STM32F207 and try to use it.

 

There is only AVR or Arduino sample as below.
I will find the LCD STM sample source.

 


Could you change the AVR source below to ST HAL based?

 

I did not think of AVR, so I did not have time.

 

Have a nice day!!
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
void I2C_init(void)
{
TWBR = 0x80; // set the bit rate
TWAR = 0x00; // set the slave address
TWSR |= 0x00; // Set the division factor
TWCR = 0X00;
DDRC=DDRC&0XF7;//PC3 check LCD BUSY
PORTC=PORTC|0X08;
}
void busy(void)
{
while(PINC&0x08); //Check LCD busy
}
// Arbitration becomes host and sends START signal
// return value: 1 for success, 0 for failure
uint8_t I2C_start(void)
{
busy();
TWCR|=(1<<TWINT)|(1<<TWEN)|(1<<TWSTA);
while(!(TWCR & (1<<TWINT)));
if(((TWSR & 0xf8)!=0x08) && ((TWSR & 0xf8)!=0x10))
return 0;
return 1;
}
// stop communication and send STOP signal)`
void I2C_stop(void)
{
TWCR|=(1<<TWINT)|(1<<TWEN)|(1<<TWSTO);
}
// Issued from the machine address and write command, that is, SLA + W, into the MT mode
// return value: 1 for success, 0 for failure
uint8_t I2C_to_write(void)
{
TWDR=0;
TWCR=(TWCR&0X0F)|(1<<TWINT)|(1<<TWEN);
while(!(TWCR &(1<<TWINT)));
if((TWSR & 0xf8)!=0x18)
return 0;
return 1;
}
// send data to the slave
// return value: 0 for failure, 1 for ACK, 2 for NOT ACK
uint8_t I2C_send(uint8_t data)
{
busy();
TWDR=data;
TWCR=(TWCR&0X0F)|(1<<TWINT)|(1<<TWEN);
while(!(TWCR & (1<<TWINT)));
if((TWSR & 0xf8)==0x28)
return 1;
else if((TWSR & 0xf8)==0x30)
return 2;
return 0;
}

Outcomes