c - How does I2C Protocol work -
i have visited on links , looked example programs i2c programming. want write own code i2c protocol. suppose ds1307 rtc , lcd connected 8051. using keil software write c program. it's difficult write whole program of i2c me, tried break program in small parts:
- module 1: define , set pins lcd , ds1307 rtc
- module 2: write c code ds1307 (make functions ds1307 such read, write)
- module 3: write c code lcd (data, command initialize, etc)
- module 4: main function
i understand module 1 looking understand module 2. again want break module 2 in small parts.
how break module 2 in small parts easy understanding? how many functions should in module2?
the module 2 i2c driver using bit banging of 8051 port. i2c protocol follows sequence. started start sequence , stopped stop sequence. can have different functions. communication started master , each slave has address. in module2, write below functions.
for example, i2 read sequence following
i2c_start(); // set i2c start sequence i2c_send(slave_address|1); send i2c slave address in read mode i2c_read_ack(); //master know slave got data while(number_of bytes){ i2c_read(); i2c_send_ack(); number_of bytes--; } i2c_nak(); //slave need know not prepare next data. i2c_stop(); //stop communication
again write on slave have below steps
i2c_start(); // set i2c start sequence i2c_send(slave_address); send i2c slave address in write mode i2c_read_ack(); //master know slave got data while(number_of bytes){ i2c_write(); i2c_read_ack(); //master know slave got data number_of bytes--; } i2c_stop(); //stop communication
i see driver @ https://circuitdigest.com/microcontroller-projects/digital-clock-using-8051-microcontroller
official i2c protocol here
Comments
Post a Comment