First, below is the schematic diagram of the CS5556 test board. The CS5556 is a 24-bit ADC.

Below is the .h file: `/*
cs5556.h
Created on: January 8, 2024
Author: OCAMAR
*/
ifndef APP_DRIVER_CS5556H
define APP_DRIVER_CS5556H
include"gConfig.h"
define Cs5556_POWER_PIN (2U)
define Cs5556_POWER_PORT (gpioPortF)
define Cs5556_SDA_PIN (12U)
define Cs5556_SDA_PORT (gpioPortB)
define Cs5556_SCL_PIN (13U)
define Cs5556_SCL_PORT (gpioPortB)
define Cs5556_DYDRB_PIN (11U)
define Cs5556_DYDRB_PORT (gpioPortC)
define CS5556_ON GPIO_PinOutSet(Cs5556_POWER_PORT,Cs5556_POWER_PIN ) //Cs5556_SDA = 1
define CS5556_OFF GPIO_PinOutClear(Cs5556_POWER_PORT,Cs5556_POWER_PIN ) //Cs5556_SDA = 0
define Cs5556_SDA_1 GPIO_PinOutSet( Cs5556_SDA_PORT,Cs5556_SDA_PIN ) //Cs5556_SDA = 1
define Cs5556_SDA_0 GPIO_PinOutClear(Cs5556_SDA_PORT,Cs5556_SDA_PIN ) //Cs5556_SDA = 0
define Cs5556_SCL_1 GPIO_PinOutSet(Cs5556_SCL_PORT,Cs5556_SCL_PIN) //Cs5556_SCL = 1
define Cs5556_SCL_0 GPIO_PinOutClear(Cs5556_SCL_PORT,Cs5556_SCL_PIN) //Cs5556_SCL = 0
define Cs5556_DIR_IN GPIO_PinModeSet(Cs5556_SDA_PORT, Cs5556_SDA_PIN,gpioModeInputPull, 1) //I/O port is input
define Cs5556_DIR_OUT GPIO_PinModeSet(Cs5556_SDA_PORT, Cs5556_SDA_PIN,gpioModePushPull, 1) //I/O port is output
define Cs5556_SDA_IN GPIO_PinInGet(Cs5556_SDA_PORT,Cs5556_SDA_PIN) //Judge Cs5556_SDA_IN level
define Cs5556_DYDRB_IN GPIO_PinInGet(Cs5556_DYDRB_PORT,Cs5556_DYDRB_PIN)
void Cs5556_I2CInit(void);
uint8_t cs5556_get_data(uint8_t reg);
void cs5556_send_data(uint8_t reg,uint8_t data);
void cs5556_sleep(void);
void cs5556_init(void);
uint32_t cs5556_get_ad(void);
endif / APP_DRIVER_CS5556H /
below .c file
void Cs5556_I2CInit(void)
{
CMU_ClockEnable(cmuClock_GPIO, true);
GPIO_PinModeSet(Cs5556_SCL_PORT, Cs5556_SCL_PIN,gpioModePushPull, 1); // I/O direction output high to prevent sinking current
GPIO_PinModeSet(Cs5556_SDA_PORT, Cs5556_SDA_PIN,gpioModePushPull, 1); // I/O direction output high to prevent sinking current
GPIO_PinModeSet(Cs5556_POWER_PORT, Cs5556_POWER_PIN,gpioModePushPull,1); // To prevent current sinking during I/O output, use the following method:
`GPIO_PinModeSet(Cs5556_DYDRB_PORT, Cs5556_DYDRB_PIN, gpioModeInputPull, 1);` // To prevent current sinking during I/O output.
`
void Cs5556_I2CREInit(void)
{
GPIO_PinModeSet(Cs5556_SCL_PORT, Cs5556_SCL_PIN, gpioModeInputPull, 1); // To prevent current sinking during I/O output, use the following method: `
GPIO_PinModeSet(Cs5556_SDA_PORT, Cs5556_SDA_PIN, gpioModeInputPull, 1); // To prevent current sinking during I/O output, use the following method: `GPIO_PinModeSet
(Cs5556_POWER_PORT, Cs5556_POWER_PIN, gpioModeInputPull, 1); //` High output in IO direction to prevent current sinking
GPIO_PinModeSet(Cs5556_DYDRB_PORT,Cs5556_DYDRB_PIN,gpioModeInputPull,1); // Output high in I/O direction to prevent current sinking
}
/****
FUNCTION NAME: Cs5556_I2CDelay();
FUNCTION: I2C bus necessary delay procedure
MODIFY DATE:
INPUT:n->delay time number equals instruction cycle number
OUTPUT:nop
RETURN:nop
****/
void Cs5556_I2CDelay(unsigned int n)
{
int i=n*10;
while(i--);
}
/****
FUNCTION NAME: I2CStart();
FUNCTION: I2C bus startup timing
MODIFY DATE:
INPUT:nop
OUTPUT:nop
RETURN:nop
****/
void Cs5556_I2CStart(void)
{
Cs5556_DIR_OUT;
Cs5556_SDA_1; Cs5556_I2CDelay (
1 ); Cs5556_SCL_1 ; Cs5556_I2CDelay(1) ; Cs5556_SDA_0 ; NAME: I2CStop(); FUNCTION:I2C bus stop timing MODIFY DATE: INPUT:nop OUTPUT:nop RETURN:nop ****/ void Cs5556_I2CStop(void) { Cs5556_DIR_OUT; Cs5556_SDA_0; Cs5556_I2CDelay(1); Cs5556_SCL_1; Cs5556_I2CDelay(1); Cs5556_SDA_1; } /**** FUNCTION NAME: I2CSendByte(); FUNCTION: I2C Send one byte of data MODIFY DATE: INPUT:ucWRData OUTPUT:nop RETURN:nop ****/ void Cs5556_I2CSendByte(unsigned char ucWRData) { Cs5556_DIR_OUT; unsigned int i; for (i = 0; i < 8; i++) { Cs5556_SCL_0; Cs5556_I2CDelay(1); if ((ucWRData >> 7) & 0x01) Cs5556_SDA_1; // Check if the highest bit is 1, if so, Cs5556_SDA = 1 else Cs5556_SDA_0; // Otherwise, Cs5556_SDA = 0 Cs5556_I2CDelay(1); Cs5556_SCL_1; Cs5556_I2CDelay(1); ucWRData <<= 1; // Shift data left by one bit, enter the next round of data transmission } Cs5556_SCL_0; // Cs5556_SDA_1; // Wait for ACK } /**** FUNCTION NAME: I2CReceiveACK(); FUNCTION: Wait for ACK signal to be received, complete one operation MODIFY DATE: INPUT:nop OUTPUT:nop RETURN:nop ****/ void Cs5556_I2CReceiveACK(void) { uint16_t ucErrTime=0; Cs5556_DIR_IN; Cs5556_SCL_1; while (Cs5556_SDA_IN) { ucErrTime++; if(ucErrTime>100) { // sync.work_mode = test_mode; Cs5556_I2CStop(); return ; } }; Cs5556_SCL_0; Cs5556_DIR_OUT; } void Cs5556_I2CReceiveNACK(void) { Cs5556_SCL_1;
Cs5556_DIR_IN;
Cs5556_I2CDelay(20);
Cs5556_SCL_0;
Cs5556_I2CDelay(1);
}
/****
FUNCTION NAME: I2CReceiveByte();
FUNCTION: Receive one byte of data
MODIFY DATE:
INPUT:nop
OUTPUT:ucRDData
RETURN:ucRDData
****/
unsigned char Cs5556_I2CReceiveByte(void)
{
unsigned char i;
unsigned char ucRDData = 0;//Return value
unsigned char ucDataBit = 0;//Data received by each clk
Cs5556_SCL_0;
Cs5556_I2CDelay(1);
Cs5556_SDA_1;
Cs5556_DIR_IN;
for (i = 0; i < 8; i++)
{
Cs5556_SCL_1;
Cs5556_I2CDelay(1);
ucDataBit = Cs5556_SDA_IN;
Cs5556_I2CDelay(1);
ucRDData = ((ucRDData << 1) | ucDataBit); // Store the data in ucRDData in sequence
Cs5556_SCL_0;
Cs5556_I2CDelay(1);
}
return (ucRDData);
}
uint8_t cs5556_get_data(uint8_t reg)
{
uint8_t temp = 0;
Cs5556_I2CStart();
Cs5556_I2CSendByte(Cs55660_W_Address);
Cs5556_I2CReceiveACK();
Cs5556_I2CSendByte(reg);
Cs5556_I2CReceiveACK();
Cs5556_I2CStart();
Cs5556_I2CSendByte(Cs55660_R_Address);
Cs5556_I2CReceiveACK();
temp = Cs5556_I2CReceiveByte();
Cs5556_I2CStop();
return temp;
}
void cs5556_send_data(uint8_t reg,uint8_t data)
{
uint8_t data2;
Cs5556_I2CStart();
Cs5556_I2CSendByte(Cs55660_W_Address);
Cs5556_I2CReceiveACK();
Cs5556_I2CSendByte(reg);
Cs5556_I2CReceiveACK();
Cs5556_I2CSendByte(data);
Cs5556_I2CReceiveACK();
Cs5556_I2CStop();
data2=cs5556_get_data(reg);
data2=data2;
}
void cs5556_sleep(void)
{
cs5556_send_data(0x03,0XF1);
cs5556_send_data(0x04,0XA6);
cs5556_send_data(0x08,0XE4);
cs5556_send_data(0x11,0X00);
cs5556_send_data(0x12,0X00);
Cs5556_I2CREInit();
}
void cs5556_init(void)
{
Cs5556_I2CInit();
cs5556_send_data(0x11,0x01); // HIRCC
delay_ms(5);
cs5556_send_data(0x03,0x4F | 0x90);// REG3
cs5556_send_data(0x04,0x20 | 0x80);// REG4
cs5556_send_data(0x00,0x11);// REG0 AIN1+ AIN1-
cs5556_send_data(0x01,0x46);// REG1 PGA GAIN 128
cs5556_send_data(0x02,0x81);// REG3 10HZ
cs5556_send_data(0x03,0x4F);// REG3
cs5556_send_data(0x04,0x20);// REG4
cs5556_send_data(0x05,0xA0);// REG5
cs5556_send_data(0x06,0x8F);// REG6
cs5556_send_data(0x07,0x4F);// REG7
cs5556_send_data(0x08,0x40);// REG8
cs5556_send_data(0x0C,0x01);// REG19
cs5556_send_data(0x0E,0x00);// SIMC0
cs5556_send_data(0x10,0x9F);// SIMTOC
}
uint32_t cs5556_get_ad(void)
{
uint32_t rt_data=0;
rt_data=cs5556_get_data(0x0b);
rt_data<<=8;
rt_data|=cs5556_get_data(0x0a);
rt_data<<=8;
rt_data|=cs5556_get_data(0x09);
rt_data>>=4;
return rt_data;
}
`
The video content does not need to be connected to a computer and can be received through a separate receiver. The output AD value changes when something is attached to the bridge and when nothing is attached.