Rev 771 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 771 | Rev 902 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2009-2011 by Claas Anders "CaScAdE" Rathje * |
3 | * admiralcascade@gmail.com * |
3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-strom/ * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-strom/ * |
5 | * * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License. * |
8 | * the Free Software Foundation; either version 2 of the License. * |
9 | * * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
14 | * * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ****************************************************************************/ |
19 | ****************************************************************************/ |
20 | 20 | ||
21 | 21 | ||
22 | /**************************************************************************** |
22 | /**************************************************************************** |
23 | * * |
23 | * * |
24 | * Most of the i²c/twi code is originally from * |
24 | * Most of the i²c/twi code is originally from * |
25 | * http://www.rn-wissen.de/index.php/TWI_Slave_mit_avr-gcc * |
25 | * http://www.rn-wissen.de/index.php/TWI_Slave_mit_avr-gcc * |
26 | * * |
26 | * * |
27 | ****************************************************************************/ |
27 | ****************************************************************************/ |
28 | 28 | ||
29 | #define I2C_BUFFER_SIZE 10 |
29 | #define I2C_BUFFER_SIZE 10 |
30 | 30 | ||
31 | // ACK |
31 | // ACK |
32 | #define TWCR_ACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC); |
32 | #define TWCR_ACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC); |
33 | // NACK |
33 | // NACK |
34 | #define TWCR_NACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC); |
34 | #define TWCR_NACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC); |
35 | // non addressed slave mode |
35 | // non addressed slave mode |
36 | #define TWCR_RESET TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC); |
36 | #define TWCR_RESET TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC); |
37 | 37 | ||
38 | 38 | ||
39 | #define CSTROM_I2C 0b00100000 // = 0x20 = 32 |
39 | #define CSTROM_I2C 0b00100000 // = 0x20 = 32 |
40 | 40 | ||
41 | volatile uint8_t i2c_rx_buffer[I2C_BUFFER_SIZE]; |
41 | volatile uint8_t i2c_rx_buffer[I2C_BUFFER_SIZE]; |
42 | 42 | ||
43 | // here we use the same for SPI and TWI |
43 | // here we use the same for SPI and TWI |
44 | extern union SPI_buffer_t SPI_buffer; |
44 | extern union SPI_buffer_t SPI_buffer; |
45 | #define i2c_tx_buffer SPI_buffer.buffer.c |
45 | #define i2c_tx_buffer SPI_buffer.buffer.c |
46 | 46 | ||
47 | // otherwise take this |
47 | // otherwise take this |
48 | //volatile uint8_t i2c_tx_buffer[I2C_BUFFER_SIZE]; |
48 | //volatile uint8_t i2c_tx_buffer[I2C_BUFFER_SIZE]; |
49 | 49 | ||
50 | 50 | ||
51 | volatile uint8_t i2c_buf_adr; |
51 | volatile uint8_t i2c_buf_adr; |
52 | 52 | ||
53 | 53 | ||
54 | void init_twi_slave (uint8_t); |
54 | void init_twi_slave (uint8_t); |
55 | 55 |