STM8 I²c's Learning

Source: Internet
Author: User
STM8 's I²c interface


1, I²c mode selection
The interface has 4 modes: from the device transmission mode, from the device receiving mode, the main device sending mode, the main device receiving mode



By default, the I²c module works in slave mode. The interface automatically switches from slave mode to main mode after the starting condition is generated


When the quorum fails or when a stop signal is sent, the switch from mode to slave mode.


2. Communication process
In main mode, the I²c interface initiates data transfer and generates a clock signal. Serial data transfer always starts with the starting condition and


Ends with a stop condition. Both the start condition and the stop condition are generated by software control in the main mode.


Related function Registers
1, i²c Control register 1 (I2C_CR1)
2, I²c control Register 2 (I2C_CR2)
3, I²c frequency register (I2C_FREQR)
allowable clock range in 1-24mhz
4, I²c self address Register LSB (I2C_OARL)
5, I²c self-address register MSB (I2c_oarh)
6, I²C Data Register (I2C_DR)
7, i²c Status Register 1 (I2C_SR1)
8, i²c Status Register 2 (I2C_SR2)
9, i²c Status Register 3 (I2C_SR3)
10. I2c_itr I²c Interrupt Register
11, I²c clock Control register low part (I2C_CCRL)
12, I²c clock Control Register high part (I2C_CCRH)




Initialization of the SI7020
void Sht20_gpio_init (void)
{
Gpio_init (I2c_sda_port, I2c_sda_pin, gpio_mode_in_pu_no_it);
Gpio_init (I2c_scl_port, I2c_scl_pin, gpio_mode_in_pu_no_it);
Sda_output ();
Scl_output ();
}


#define SDA_OUTPUT () do{i2c_sda_port->ddr |=i2c_sda_pin;} while (0)
#define SCL_OUTPUT () do{i2c_scl_port->ddr |=i2c_scl_pin;} while (0)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.