This post was last edited by hehung on 2019-7-28 23:35
I've had this board for a long time, but something delayed me for the past two weeks. I took it out this week and planned to have some fun with it.
I spent most of the day downloading and checking information, but there is still a lot of information that cannot be downloaded. I guess I need to use scientific Internet access to download it.
Checking the manual, it says that a matching stm32 board is needed, but I don't have that kind of board, and I use hardware IIC, which is difficult to use with the stm32 program. So I plan to use other boards to use analog IIC to implement it.
Of course, we started with the simplest STTS751, which is a temperature chip. By looking at the schematic diagram and chip manual, we found the corresponding chip on the board. As shown below:
View the schematic:
As can be seen from the schematic diagram, this chip is connected to I2C1 of the IIC bus and is powered by 2.5V, but don't worry about this, there is a voltage conversion chip at the back that can convert the input voltage Vio into 2.5V.
Where is I2C1 connected to on the schematic?
Now that we have found the position shown in the picture above, we can make the connection through the IIC pins brought out on the board.
PS: I connected to J on the board at first, but found that communication failed. This took me a lot of time. At first I thought it was because the IIC address of the slave was wrong. I modified it a lot but it still didn’t work. Then I thought it was a problem with the communication protocol, but my OLED is also IIC and can communicate normally. Finally I almost collapsed. I checked the wiring cap written on the schematic diagram and it can be used with I2C2 after connecting it??????
Finally, I found an I2C1 interface on the schematic diagram and it worked fine after plugging it in. It was strange. Then I changed the IIC pin of OLED to the IIC pin of J2 on the board.
The interface is found to be usable normally? ? ? ? Ask an expert to answer
As shown in the picture above, I used the two pins 21 and 20 in the picture. After plugging them in, I found that communication was normal.
View the manual:
This chip also supports a communication protocol called SMbus, which I have heard of, I am using IIC.
There is a register summary:
Points out all the register addresses and functions used by STTS751, among which the most important registers are 0x00, 0x02, 0xFE.
I use these in my program.
0x00 is the high bit of the temperature reading.
0x02 is the low bit for reading temperature.
0xfe is used to read the factory ID, which can be used to identify the chip and also to verify whether your communication is normal.
These registers do not require additional operations and can be read directly.
Write the program:
First is the IIC program. Simulating IIC is a very simple communication, so I won’t go into details here.
STTS751 uses IIC to write data:
//STTS751写
static void IIC_WrDat_STTS751(uint8_t IIC_Add, uint8_t IIC_Reg, uint8_t IIC_Data)
{
uint8_t succ, stime=0;
IIC_Start();
IIC_Send_Byte(IIC_Add);
IIC_Wait_Ack();
IIC_Send_Byte(IIC_Reg); //write data
IIC_Wait_Ack();
IIC_Send_Byte(IIC_Data);
IIC_Wait_Ack();
IIC_Stop();
}
STTS751 read data:
//STTS751读
static uint8_t IIC_Read_STTS751(uint8_t IIC_Add, uint8_t IIC_Reg)
{
char ret;
uint8_t ret_suc = 1;
IIC_Start();
IIC_Send_Byte(IIC_Add & 0xfe);
ret_suc = IIC_Wait_Ack();
if(ret_suc == 1)
return 1; //失败
IIC_Send_Byte(IIC_Reg);
ret_suc = IIC_Wait_Ack();
if(ret_suc == 1)
return 1; //失败
IIC_Start();
IIC_Send_Byte(IIC_Add | 0x01);
ret_suc = IIC_Wait_Ack();
ret=IIC_Read_Byte(1);
IIC_Stop();
return (uint8_t)ret;
}
Set registers, read registers:
//设置寄存器
void Set_Reg_STTS751(uint8_t add, uint8_t reg, uint8_t dat)
{
IIC_WrDat_STTS751(add, reg, dat);
}
//读取寄存器
uint8_t Get_Reg_STTS751(uint8_t add, uint8_t reg)
{
return IIC_Read_STTS751(add, reg);
}
Read temperature high byte, read temperature low byte, read factory ID, read product ID:
int Read_Temperature_H_STTS751(void)
{
return Get_Reg_STTS751(STTS751_ADDR, STTS751_REG_TEMPVH);
}
int Read_Temperature_L_STTS751(void)
{
return Get_Reg_STTS751(STTS751_ADDR, STTS751_REG_TEMPVL);
}
uint8_t Read_STTS751_Manualfacture_ID(void)
{
return (Get_Reg_STTS751(STTS751_ADDR, STTS751_REG_MANUALID));
}
uint8_t Read_STTS751_Product_ID(void)
{
return (Get_Reg_STTS751(STTS751_ADDR, STTS751_REG_PRODUCT));
}
Serial port sending:
void Send_Uart_STTS751(void)
{
char str[35] = {0};
send_str((uint8_t *)"<-----------START--------->\r\n");
sprintf(str,"Temp:%d.%d\r\n",Read_Temperature_H_STTS751(),Read_Temperature_L_STTS751());
send_str((uint8_t *)str);
sprintf(str,"M_ID:%X\r\n",Read_STTS751_Manualfacture_ID());
send_str((uint8_t *)str);
sprintf(str,"P_ID:%d\r\n",Read_STTS751_Product_ID());
send_str((uint8_t *)str);
send_str((uint8_t *)"<------------END---------->\r\n");
}
OLED Display:
void OLED_Display_STTS751(void)
{
char str_dis1[10], str_dis2[10];
OLED_Clear();
sprintf(str_dis1,"Temp:%d.%d\r\n",Read_Temperature_H_STTS751(),Read_Temperature_L_STTS751());
sprintf(str_dis2,"ID :%d\r\n",Read_STTS751_Manualfacture_ID());
OLED_ShowString(0,16,(uint8_t *)str_dis1,16,1);
OLED_ShowString(0,32,(uint8_t *)str_dis2,16,1);
OLED_Refresh_Gram();
}
Some macro definitions:
#define STTS751_REG_STATUS (0x01U)
#define STTS751_REG_CONFIG (0x03U)
#define STTS751_REG_CONRAT (0x04U)
#define STTS751_REG_TEMPVH (0x00U)
#define STTS751_REG_TEMPVL (0x02U)
#define STTS751_REG_TEMPHH (0x05U)
#define STTS751_REG_TEMPHL (0x06U)
#define STTS751_REG_TEMPLH (0x07U)
#define STTS751_REG_TEMPLL (0x08U)
#define STTS751_REG_ONESHOT (0x0FU)
#define STTS751_REG_MANUALID (0xFEU)
#define STTS751_REG_PRODUCT (0xFDU)
#define STTS751_ADDR 0x94U
The above is the main code to complete the STTS751 reading.
The data received by the serial port shows that the temperature of the sensor increases when the sensor is squeezed by hand:
Here are the results:
Reading temperature:
If you pinch the STTS751 sensor with your hand, the temperature will rise:
Display of the entire wiring:
Well, I will start writing the rest next week, time is running out...
|