Subversion Repositories Projects

Rev

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
Console listens at 8n1 19200... Commands are explained there... 
21
Console listens at 8n1 19200... Commands are explained there... 
22
 
22
 
23
 
23
 
24
#############################################################################
24
#############################################################################
25
i2c/twi Sample snipplet
25
i2c/twi Sample snipplet
26
    // i2c master libary by Peter Fleury used in this example
26
    // i2c master libary by Peter Fleury used in this example
27
    // http://homepage.hispeed.ch/peterfleury/avr-software.html#libs
27
    // http://homepage.hispeed.ch/peterfleury/avr-software.html#libs
28
 
28
 
29
    #define CSTROM_I2C 0x20
29
    #define CSTROM_I2C 0x20
30
        
30
        
31
    i2c_init();
31
    i2c_init();
32
    sei(); 
32
    sei(); 
33
    
33
    
34
    union SPI_buffer_t SPI_buffer;
34
    union SPI_buffer_t SPI_buffer;
35
		// @see http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=Projects&path=%2FC-OSD%2Ftrunk%2Fspi.h
35
		// @see http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=Projects&path=%2FC-OSD%2Ftrunk%2Fspi.h
36
 
36
 
37
		if(!(i2c_start(CSTROM_I2C+I2C_WRITE))) { // check for slave ready
37
		if(!(i2c_start(CSTROM_I2C+I2C_WRITE))) { // check for slave ready
38
			i2c_write(0x00); // start with buffer address 0
38
			i2c_write(0x00); // start with buffer address 0
39
		    i2c_rep_start(CSTROM_I2C+I2C_READ); // start reading
39
		    i2c_rep_start(CSTROM_I2C+I2C_READ); // start reading
40
			for (uint8_t i = 0; i < 9; i++) { // loop through first 9 positions
40
			for (uint8_t i = 0; i < 9; i++) { // loop through first 9 positions
41
				SPI_buffer.buffer.c[i] = i2c_readAck();
41
				SPI_buffer.buffer.c[i] = i2c_readAck();
42
			}
42
			}
43
			SPI_buffer.buffer.c[9] = i2c_readNak(); // last position does not take ACK
43
			SPI_buffer.buffer.c[9] = i2c_readNak(); // last position does not take ACK
44
			i2c_stop();
44
			i2c_stop();
45
		}
45
		}
46
		uart_puts(itoa(SPI_buffer.data.volt, s, 10));
46
		uart_puts(itoa(SPI_buffer.data.volt, s, 10));
47
		uart_puts_pgm(PSTR("V\r\n"));
47
		uart_puts_pgm(PSTR("V\r\n"));
48
#############################################################################
48
#############################################################################