add take data sample of 12bit and send to peripheral

This commit is contained in:
Sanyog Nevase Nevase 2024-10-29 20:18:35 +05:30
parent b6c18dbd2e
commit 598911870c
1 changed files with 15 additions and 3 deletions

18
main.c
View File

@ -15,8 +15,7 @@ void I2C0_init(void) {
SYSCTL_RCGCGPIO_R |= 0x02; // GPIO PORTB CLOCK ENABLE SYSCTL_RCGCGPIO_R |= 0x02; // GPIO PORTB CLOCK ENABLE
while ((SYSCTL_PRGPIO_R & 0x02) == 0) while ((SYSCTL_PRGPIO_R & 0x02) == 0)
{ { // DELAY TO ENSURE CLOCK IS STABILIZED
// DELAY TO ENSURE CLOCK IS STABILIZED
}; };
GPIO_PORTB_AFSEL_R |= 0x0C; // ENABLE ALERNATE FUNCTION FOR PB2 AND PB3 GPIO_PORTB_AFSEL_R |= 0x0C; // ENABLE ALERNATE FUNCTION FOR PB2 AND PB3
@ -29,7 +28,7 @@ void I2C0_init(void) {
I2C0_MTPR_R = 0x07; // SET CLOCK I2C0_MTPR_R = 0x07; // SET CLOCK
} }
void I2C0_WRITE(uint8_t PERIPHERAL_ADDRESS, uint8_t ANALOG_SAMPLE_MSB, uint8_t ANALOG_SAMPLE_LSB) void I2C0_SEND(uint8_t PERIPHERAL_ADDRESS, uint8_t ANALOG_SAMPLE_MSB, uint8_t ANALOG_SAMPLE_LSB) // DEFINE I2C0 SEND FUNCTION TO PERIPHERAL ADDRESS AND 12 BIT DATA
{ {
I2C0_MSA_R = (PERIPHERAL_ADDRESS << 1); // SET PERIPHERAL ADDRESS, WRITE I2C0_MSA_R = (PERIPHERAL_ADDRESS << 1); // SET PERIPHERAL ADDRESS, WRITE
I2C0_MDR_R = ANALOG_SAMPLE_MSB; // MSB I2C0_MDR_R = ANALOG_SAMPLE_MSB; // MSB
@ -60,6 +59,19 @@ void delay(int us)
STCTRL &= ~ENABLE; // STOP TIMER STCTRL &= ~ENABLE; // STOP TIMER
} }
#define MCP4725_ADDRESS 0x60 // PERIPHERAL I2C ADDRESS
void AOUT(uint16_t ANALOG_SAMPLE)
{
uint8_t ANALOG_SAMPLE_MSB = (ANALOG_SAMPLE >> 8) & 0x0F; // TAKE UPPER 4 BITS OF 12 BIT DATA TO TRANSMIT
uint8_t ANALOG_SAMPLE_LSB = ANALOG_SAMPLE & 0xFF; // TAKE LOWER 8 BITS OF 12 BIT DATA TO TRANSMIT
I2C0_SEND(MCP4725_ADDRESS, ANALOG_SAMPLE_MSB, ANALOG_SAMPLE_LSB); //SEND 12 BIT DATA
}
int main(void) int main(void)
{ {
systick_setting(); // SysTick setup systick_setting(); // SysTick setup