Im actually using IP block design in my vivado. Im using two AXI IIC bus. one is connected to SHT21 and other is connected to 0.96OLED. Ive generated bitstream got my xsa file and Ive written a vitis code which i ve attached here..
#include <stdio.h>
#include "xiic.h"
#include "xil_printf.h"
#include "xparameters.h"
#include <sleep.h> // Include the sleep library for usleep function
#define SHT21_IIC_ADDRESS 0x40
#define OLED_IIC_ADDRESS 0x3C
#define IIC_SCLK_RATE 100000
XIic IicSht21Instance;
XIic IicOledInstance;
int main() {
// Initialize I2C for SHT21 sensor
XIic_Config *IicSht21Config;
IicSht21Config = XIic_LookupConfig(XPAR_AXI_IIC_0_DEVICE_ID);
XIic_CfgInitialize(&IicSht21Instance, IicSht21Config, IicSht21Config->BaseAddress);
XIic_SetGpOutput(&IicSht21Instance, 0x01);
XIic_SetAddress(&IicSht21Instance, XII_ADDR_TO_SEND_TYPE, SHT21_IIC_ADDRESS);
// Initialize I2C for OLED display
XIic_Config *IicOledConfig;
IicOledConfig = XIic_LookupConfig(XPAR_AXI_IIC_1_DEVICE_ID);
XIic_CfgInitialize(&IicOledInstance, IicOledConfig, IicOledConfig->BaseAddress);
XIic_SetGpOutput(&IicOledInstance, 0x01);
XIic_SetAddress(&IicOledInstance, XII_ADDR_TO_SEND_TYPE, OLED_IIC_ADDRESS);
// Read data from SHT21 sensor
u8 readDataSht21[2];
XIic_MasterRecv(&IicSht21Instance, readDataSht21, sizeof(readDataSht21));
// Process temperature and humidity data from readDataSht21
float temperature = ((readDataSht21[0] << 8) + readDataSht21[1]) * 175.72 / 65536 - 46.85;
float humidity = ((readDataSht21[0] << 8) + readDataSht21[1]) * 125.0 / 65536 - 6;
char oledData[128];
snprintf(oledData, sizeof(oledData), "Temperature: %.2f Humidity: %.2f", temperature, humidity);
// Write data to OLED display
u8 writeDataOled[33];
writeDataOled[0] = 0x00;
strncpy((char*)(writeDataOled + 1), oledData, sizeof(writeDataOled) - 1);
XIic_MasterSend(&IicOledInstance, writeDataOled, sizeof(writeDataOled));
// Wait for some time to allow the OLED display to update
usleep(1000000); // Sleep for 1 second (1,000,000 microseconds)
return 0;
}
Ive created build and ive run it but i dont see any output. I want to know whether this code is correct or not and I want to know whether there are library header files for SHT21 and 0.96OLED to write the code. Ive searched it but only found it for arduino. Im confused whether i can use those libraries cause they've mentioned its only for ardunio. I've checked if my sensor is working or not by printing its value in the putty terminal but the temperature values are not changing it was showing constant value of -4°©