Last active
November 22, 2016 22:19
-
-
Save dvdfreitag/fa2da7c9121e26515921f02ae2ced271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _HARDWARE_TWI_ | |
#include "MCP4728.h" | |
#define TWI_BAUD 0x3B // (F_CPU / (2 * TWI_SPEED)) - 5 (truncated to byte) | |
int main(void) | |
{ | |
// Configure TWIE | |
// Clear Bit 6 corresponding to TWIE | |
PR.PRPE &= ~PR_TWI_bm; | |
// Set pins to wired and pulled up | |
PORTE.PIN0CTRL = PORT_OPC_WIREDANDPULL_gc; | |
PORTE.PIN1CTRL = PORT_OPC_WIREDANDPULL_gc; | |
// Set the TWIE enable bit | |
TWIE.MASTER.CTRLA = TWI_MASTER_ENABLE_bm; | |
// Set the TWIE Master baud rate | |
TWIE.MASTER.BAUD = TWI_BAUD; | |
// Set the bus STATUS register to idle | |
TWIE.MASTER.STATUS = TWI_MASTER_BUSSTATE_IDLE_gc; | |
// Set LDAC to high and output | |
PORTA.OUTSET = 0x01; | |
PORTA.DIRSET = 0x01; | |
// Using TWIE, PA0 for LDAC, and default address | |
MCP4728_Init(&TWIE, &PORTA, 0x01, 0x00); | |
// SDA is PE0, SCL is PE1 | |
uint8_t address = MCP4728_ReadAddress(&PORTE, 0x01, 0x02); | |
// Set outputs to a random value | |
uint16_t values[] = { 0x3FF, 0x3FF, 0x3FF, 0x3FF }; | |
MCP4728_FastWrite((uint8_t *)values, 4); | |
while (1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment