Subversion Repositories group.electronics

Rev

Rev 42 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 42 Rev 56
Line 1... Line 1...
1
#include <avr/io.h>
1
#include <avr/io.h>
2
#include "wire.h"
2
#include "wire.h"
3
#include "twi.h"
3
#include "twi.h"
4
 
4
 
5
#define		MAX_BUFFER	4
-
 
6
 
-
 
7
void i2c_master(void) {
5
void i2c_master(void) {
8
	wire.rxBufferIndex = 0;
6
	wire.rxBufferIndex = 0;
9
	wire.rxBufferLength = 0;
7
	wire.rxBufferLength = 0;
10
 
8
 
11
	wire.rxBufferIndex = 0;
9
	wire.rxBufferIndex = 0;
Line 14... Line 12...
14
	twi_init();
12
	twi_init();
15
}
13
}
16
 
14
 
17
void i2c_slave(uint8_t address) {
15
void i2c_slave(uint8_t address) {
18
	twi_setAddress(address);
16
	twi_setAddress(address);
19
	//twi_attachSlaveTxEvent(&onRequestService);
17
	twi_attachSlaveTxEvent(&i2c_onRequestService);
20
	//twi_attachSlaveRxEvent(&onReceiveService);
18
	twi_attachSlaveRxEvent(&i2c_onReceiveService);
21
	i2c_master();
19
	i2c_master();
22
}
20
}
23
 
21
 
24
uint8_t i2c_requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop) {
22
uint8_t i2c_requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop) {
25
	if (quantity > MAX_BUFFER) {
23
	if (quantity > MAX_BUFFER) {
Line 52... Line 50...
52
}
50
}
53
 
51
 
54
uint8_t i2c_writeByte(uint8_t data) {
52
uint8_t i2c_writeByte(uint8_t data) {
55
	if (wire.transmitting) {
53
	if (wire.transmitting) {
56
		if (wire.txBufferLength >= MAX_BUFFER) {
54
		if (wire.txBufferLength >= MAX_BUFFER) {
57
			//setWriteError();
-
 
58
			return 0;
55
			return 0;
59
		}
56
		}
60
 
57
 
61
		wire.txBuffer[wire.txBufferIndex] = data;
58
		wire.txBuffer[wire.txBufferIndex] = data;
62
		++wire.txBufferIndex;
59
		++wire.txBufferIndex;