The I2C module of STM8S can not only receive and send data, but also convert data from serial to parallel data when receiving, and convert data from parallel to serial data when sending. You can enable or disable interrupts. The interface is connected to the I2C bus through data pins (SDA) and clock pins (SCL). Allows connection to standard (up to 100kHz) or fast (up to 400kHz) I2C bus. 1. 4 modes of I2C â— Send mode from device â— Receive mode from device â— Main device sending mode â— Master receiving mode 2. The main features of I2C â— Parallel bus/I2C bus protocol converter â— Multi-master function: the module can be used as a master device or as a slave device â—I2C master device function ─ Generate start and stop signals â—I2C slave function ─ Programmable I2C address detection ─ Stop bit detection â— Generate and detect 7-bit/10-bit address and general call â— Support different communication speeds ─ Standard speed (up to 100 kHz) ─ Fast (up to 400 kHz) â— Status flag: ─ Transmitter/receiver mode flag ─I2C Bus Busy Flag ─ Loss of arbitration in main mode ─ Address/data transmission response (ACK) error ─ Detect wrong start or stop condition ─ Data overload or underload when the clock stretching function is prohibited â—3 types of interrupts ─1 communication interruption ─1 error interrupt ─1 wake-up interrupt â— Wake-up function ─ If an address match is detected in the slave mode, the MCU can be woken up from the low-power mode â— Optional clock stretching function 3. The sequence of operations required by the main mode â— Set the input clock of the module in the I2C_FREQR register to generate the correct timing â— Configure the clock control register â— Configure the rise time register â— Programming the I2C_CR1 register to start the peripheral â— Set the START bit in the I2C_CR1 register to 1, to generate a start condition â—The input clock frequency of the I2C module must be at least: â— In standard mode: 1MHz â— In fast mode: 4MHz The project code provided in this article is based on the previous software project "STM8S-A04_UART basic sending and receiving data" by adding I2C interface modification. The way to read and write EEPROM is different from the previous "analog I2C read and write" method. 2. Hardware I2C initialization void I2C_Initializes(void) { CLK_PeripheralClockConfig (CLK_PERIPHERAL_I2C, ENABLE); I2C_Cmd (ENABLE); I2C_Init (I2C_SPEED, I2C_SLAVE_ADDRESS7, I2C_DUTYCYCLE_2, I2C_ACK_CURR, I2C_ADDMODE_7BIT, 16); } I2C_SPEED: I2C speed, generally 100K-400K I2C_SLAVE_ADDRESS7: Slave device address. When used as a master device, this address has no effect. I2C_DUTYCYCLE_2: Fast mode I2C_ACK_CURR: Acknowledge I2C_ADDMODE_7BIT: Device address bits 16: Input clock (unit M) 3. EEPROM_WriteByte write one byte Writing a byte is divided into 5 steps: void EEPROM_WriteByte (uint16_t Addr, uint8_t Data) { while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY)); /* 1. Start */ I2C_GenerateSTART(ENABLE); while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT)); /* 2. Device address/write*/ I2C_Send7bitAddress (EEPROM_DEV_ADDR, I2C_DIRECTION_TX); while(!I2C_CheckEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); /* 3. Data address*/ #if (8 == EEPROM_WORD_ADDR_SIZE) I2C_SendData ((Addr&0x00FF)); while (! I2C_CheckEvent (I2C_EVENT_MASTER_BYTE_TRANSMITTED)); #else I2C_SendData((uint8_t)(Addr》》8)); while (! I2C_CheckEvent (I2C_EVENT_MASTER_BYTE_TRANSMITTED)); I2C_SendData((uint8_t)(Addr&0x00FF)); while (! I2C_CheckEvent (I2C_EVENT_MASTER_BYTE_TRANSMITTED)); #endif /* 4. Write a byte of data*/ I2C_SendData(Data); while (! I2C_CheckEvent (I2C_EVENT_MASTER_BYTE_TRANSMITTED)); /* 5.Stop*/ I2C_GenerateSTOP(ENABLE); } 4. EEPROM_ReadByte reads one byte Reading a byte requires 2 more steps than writing a byte. The reason is that there is a switching process from writing addresses to reading data when reading. void EEPROM_ReadByte (uint16_t Addr, uint8_t *Data) { while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY)); /* 1. Start */ I2C_GenerateSTART(ENABLE); while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT)); /* 2. Device address/write*/ I2C_Send7bitAddress (EEPROM_DEV_ADDR, I2C_DIRECTION_TX); while(!I2C_CheckEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); /* 3. Data address*/ #if (8 == EEPROM_WORD_ADDR_SIZE) I2C_SendData ((Addr&0x00FF)); while (! I2C_CheckEvent (I2C_EVENT_MASTER_BYTE_TRANSMITTED)); #else I2C_SendData((uint8_t)(Addr》》8)); while (! I2C_CheckEvent (I2C_EVENT_MASTER_BYTE_TRANSMITTED)); I2C_SendData((uint8_t)(Addr&0x00FF)); while (! I2C_CheckEvent (I2C_EVENT_MASTER_BYTE_TRANSMITTED)); #endif /* 4. Start over*/ I2C_GenerateSTART(ENABLE); while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT)); /* 5. Device address/read*/ I2C_Send7bitAddress (EEPROM_DEV_ADDR, I2C_DIRECTION_RX); while(!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); /* 6. Read one byte of data*/ I2C_AcknowledgeConfig (I2C_ACK_NONE); while(I2C_GetFlagStatus(I2C_FLAG_RXNOTEMPTY) == RESET); *Data = I2C_ReceiveData(); /* 7.Stop*/ I2C_GenerateSTOP(ENABLE); } PCB Spring Terminal Block Section
PCB Spring Terminal Block
It is a new type of terminal block with spring device, which has been widely used in the world's electrical and electronic engineering industry: lighting, elevator lifting control, instruments, power supply, chemistry and automobile power, etc.
Spring type terminal block PCB Spring Terminal Block ShenZhen Antenk Electronics Co,Ltd , https://www.antenkconn.com
Spring type PCB terminal, the connection mode is divided into cage spring connection and butterfly spring connection, which is fast and convenient for wiring and improves the operation efficiency.
It can be used to connect all types of conductors with cross-section of 0.2mm to 16mm, with spacing of 2.5mm-15.0mm.
STM8 hardware I2C knowledge