Skip to content
Snippets Groups Projects
Commit 909c7cc3 authored by Markus Scheck's avatar Markus Scheck
Browse files

deleted unused programms

parent b5682c64
No related branches found
No related tags found
No related merge requests found
Showing
with 6 additions and 133 deletions
#include <avr/io.h>
//initialize pin change interrupt and data directions
inline void init_pc(void) {
// enable/ setup output port
DDRA = 0xff; // all out
PORTA = 0x00; // all low
}
// all functions inline to save execution time
// initialize timer for time measurement
inline void timer_init(void);
// start time measurement
inline void timer_start(void);
// stop time measurement, return ticks
inline uint32_t timer_stop(void);
// get timer ticks
inline uint32_t timer_ticks(void);
// This module uses TIMER1 to keep track of time
#include "timer_1.h"
#include <avr/interrupt.h>
uint32_t overflow_count;
#define TIMER_MASK (1<<CS10)
inline void timer_init(void) {
// enable overflow interrupt
TIMSK1 |= (1<<TOIE1);
}
inline void timer_start(void) {
//disable interrupts globally
cli();
//clear out timer counting register
TCNT1 = 0;
//clear overflow count
overflow_count = 0;
// set up clock source
// we have a 16MHz Clock
// and a 16 Bit timer
// Use a prescaler of 256 -> 16/256 = 62.5kHz
TCCR1B |= TIMER_MASK;
//enable interrupts
sei();
}
inline uint32_t timer_ticks(void) {
return TCNT1 ^ (overflow_count << 16);
}
inline uint32_t timer_stop(void) {
// stop timer clock
TCCR1B &= ~(TIMER_MASK);
return timer_ticks();
}
ISR(TIMER1_OVF_vect) {
overflow_count++;
}
...@@ -88,7 +88,9 @@ inline void tp_i2c(uint16_t len) { ...@@ -88,7 +88,9 @@ inline void tp_i2c(uint16_t len) {
transmit_data(0xff); transmit_data(0xff);
} }
transmit_stop(); transmit_stop();
delayMicroseconds(20); delayMicroseconds(5); // wait for transmission of stop
// may need to be altered for slow bit speeds
// hardware needs time to latch the request for a stop
//read data from slave //read data from slave
transmit_start(); transmit_start();
transmit_sla_x(1); transmit_sla_x(1);
...@@ -96,6 +98,8 @@ inline void tp_i2c(uint16_t len) { ...@@ -96,6 +98,8 @@ inline void tp_i2c(uint16_t len) {
recv_data(); recv_data();
} }
transmit_stop(); transmit_stop();
delayMicroseconds(20); delayMicroseconds(5); // wait for transmission of stop
// may need to be altered for slow bit speeds
// hardware needs time to latch the request for a stop
} }
} }
File deleted
// all functions inline to save execution time
inline void init_i2c(void);
#include <avr/interrupt.h>
#include <util/twi.h>
#define SLA_ADDR 1
inline void init_i2c(void) {
// Setup as slave, ADDR 1
TWAR = SLA_ADDR<<1;
TWCR = (1<<TWEA)|(1<<TWEN);
}
uint16_t recv_bytes = 0;
inline void tp_i2c(void) {
while(1) {
// wait for a change to occur on i2c
while(!(TWCR&(1<<TWINT)));
//check status
uint8_t stat = TWSR&0xF8;
switch(stat) {
// do nothing for states that do not signal errors or received data
case 0x60:
case 0x68:
case 0x70:
case 0x78:
case 0xa0:
break;
// for data reception, do...
case 0x80:
case 0x90:
// count received bytes
recv_bytes++;
//if 1kb received, notify timer
if(recv_bytes >= 1024) {
//Set PORTA high
PORTA = 0xff;
PORTA = 0x00;
recv_bytes = 0;
}
break;
default:
Serial.println(stat);
}
// Clear flag on I2C, allow for further data/events
TWCR = (1<<TWEA)|(1<<TWEN)|(1<<TWINT);
}
}
#include "pinchange.h"
#include <avr/io.h>
int main(void) {
// initialize pin change
init_pc();
// initialize i2c
init_i2c();
// initialize serial
Serial.begin(115200);
while(1) {
// receive packages
tp_i2c();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment