From 598911870ca1adf3640fcacf79cde9efce223640 Mon Sep 17 00:00:00 2001 From: Sanyog Date: Tue, 29 Oct 2024 20:18:35 +0530 Subject: [PATCH] add take data sample of 12bit and send to peripheral --- main.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 4fee8ee..ec2a112 100644 --- a/main.c +++ b/main.c @@ -15,8 +15,7 @@ void I2C0_init(void) { SYSCTL_RCGCGPIO_R |= 0x02; // GPIO PORTB CLOCK ENABLE 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 @@ -29,7 +28,7 @@ void I2C0_init(void) { 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_MDR_R = ANALOG_SAMPLE_MSB; // MSB @@ -60,6 +59,19 @@ void delay(int us) 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) { systick_setting(); // SysTick setup