cancel
Showing results for 
Search instead for 
Did you mean: 

12864B I2C LCD I will ask. (STM32F429)

Study Yahoo
Associate III
Posted on November 29, 2017 at 07:51

Hi everyone

That link page 12864 I2C LCD

(

https://community.st.com/external-link.jspa?url=http%3A%2F%2Fzhongbest.com%2F2017%2F04%2F05%2Fi2c-lcd12864%25E6%2598%25BE%25E7%25A4%25BA%25E5%25B1%258F%25E5%2585%25BC%25E5%25AE%25B9arduino%2F

)

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;

}

1 REPLY 1
shane mattner
Senior
Posted on December 11, 2017 at 19:54

Have you tried setting up a project with CubeMX then using the HAL commands like 'HAL_I2C_Master_Transmit'?  CubeMX is really simple and you can find tutorials on YouTube.