Create basic i2c skeleton with interrupts
I2C init function has been created. Interrupts have been made for each I2C interrupt. Which interrupt does what is currently unknown. See #1
This commit is contained in:
parent
45bc800397
commit
ac78f33c98
32
prosjekt.X/i2c.c
Normal file
32
prosjekt.X/i2c.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include "i2c.h"
|
||||||
|
|
||||||
|
void init_i2c(void) {
|
||||||
|
// Initialize the control A register
|
||||||
|
TWI0.CTRLA = TWI_INPUTLVL_I2C_gc // I2C voltage transition level
|
||||||
|
| TWI_SDASETUP_4CYC_gc // Four clock cycles setup time
|
||||||
|
| TWI_SDAHOLD_50NS_gc // 50ns SDA hold time
|
||||||
|
| TWI_FMPEN_OFF_gc // Standard SPI timing
|
||||||
|
;
|
||||||
|
|
||||||
|
// The device's slave address
|
||||||
|
TWI0.SADDR = 0x42;
|
||||||
|
|
||||||
|
// Enable acting as a slave
|
||||||
|
TWI0.SCTRLA = TWI_DIEN_bm // Enable data interrupt
|
||||||
|
| TWI_PIEN_bm // Enable stop flag interrupt
|
||||||
|
| TWI_SMEN_bm // Enable smart mode
|
||||||
|
| TWI_ENABLE_bm // Enable acting as a slave
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Figure out which interrupt does what
|
||||||
|
|
||||||
|
// Interrupt vector
|
||||||
|
ISR(TWI0_TWIS_vect) {
|
||||||
|
asm('nop');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interrupt vector
|
||||||
|
ISR(TWI0_TWIM_vect) {
|
||||||
|
asm('nop');
|
||||||
|
}
|
||||||
26
prosjekt.X/i2c.h
Normal file
26
prosjekt.X/i2c.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* File: i2c.h
|
||||||
|
* Author: sebgab
|
||||||
|
*
|
||||||
|
* Created on March 6, 2024, 1:53 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef I2C_H
|
||||||
|
#define I2C_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Include the IO for I2C
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
// Initialize the I2C bus
|
||||||
|
void init_i2c(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* I2C_H */
|
||||||
@ -5,6 +5,7 @@
|
|||||||
displayName="Header Files"
|
displayName="Header Files"
|
||||||
projectFiles="true">
|
projectFiles="true">
|
||||||
<itemPath>command-handler.h</itemPath>
|
<itemPath>command-handler.h</itemPath>
|
||||||
|
<itemPath>i2c.h</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="LinkerScript"
|
<logicalFolder name="LinkerScript"
|
||||||
displayName="Linker Files"
|
displayName="Linker Files"
|
||||||
@ -15,6 +16,7 @@
|
|||||||
projectFiles="true">
|
projectFiles="true">
|
||||||
<itemPath>main.c</itemPath>
|
<itemPath>main.c</itemPath>
|
||||||
<itemPath>command-handler.c</itemPath>
|
<itemPath>command-handler.c</itemPath>
|
||||||
|
<itemPath>i2c.c</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="ExternalFiles"
|
<logicalFolder name="ExternalFiles"
|
||||||
displayName="Important Files"
|
displayName="Important Files"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user