Browse Source

Fix errors.

Vladimir N. Shilov 3 years ago
parent
commit
bb7e6be390
7 changed files with 36 additions and 33 deletions
  1. 1 1
      Dryer.cbp
  2. 24 24
      Dryer.layout
  3. 1 1
      Makefile
  4. 2 0
      inc/i2c.h
  5. 1 2
      inc/main.h
  6. 5 0
      src/i2c.c
  7. 2 5
      src/main.c

+ 1 - 1
Dryer.cbp

@@ -35,7 +35,7 @@
 			<Add option="-Wall" />
 			<Add option="-Wall" />
 			<Add option="-mmcu=atmega328p" />
 			<Add option="-mmcu=atmega328p" />
 			<Add option="-std=gnu11" />
 			<Add option="-std=gnu11" />
-			<Add option="-DF_CPU=8000000UL" />
+			<Add option="-DF_CPU=16000000UL" />
 			<Add directory="lib" />
 			<Add directory="lib" />
 			<Add directory="inc" />
 			<Add directory="inc" />
 		</Compiler>
 		</Compiler>

+ 24 - 24
Dryer.layout

@@ -2,64 +2,64 @@
 <CodeBlocks_layout_file>
 <CodeBlocks_layout_file>
 	<FileVersion major="1" minor="0" />
 	<FileVersion major="1" minor="0" />
 	<ActiveTarget name="Debug" />
 	<ActiveTarget name="Debug" />
-	<File name="lib\rtos\rtos.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="inc\sensor.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 		<Cursor>
-			<Cursor1 position="2098" topLine="0" />
+			<Cursor1 position="393" topLine="0" />
 		</Cursor>
 		</Cursor>
 	</File>
 	</File>
-	<File name="inc\sensor.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="inc\main.h" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 		<Cursor>
-			<Cursor1 position="393" topLine="0" />
+			<Cursor1 position="323" topLine="0" />
 		</Cursor>
 		</Cursor>
 	</File>
 	</File>
-	<File name="lib\tinyavrlib\num2str.c" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="src\main.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 		<Cursor>
-			<Cursor1 position="2700" topLine="43" />
+			<Cursor1 position="460" topLine="0" />
 		</Cursor>
 		</Cursor>
 	</File>
 	</File>
-	<File name="inc\i2c.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\ssd1306xled\ssd1306xled.c" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 		<Cursor>
-			<Cursor1 position="54" topLine="0" />
+			<Cursor1 position="5802" topLine="113" />
 		</Cursor>
 		</Cursor>
 	</File>
 	</File>
-	<File name="src\i2c.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\ssd1306xled\ssd1306xledtx.c" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 		<Cursor>
-			<Cursor1 position="318" topLine="0" />
+			<Cursor1 position="2433" topLine="14" />
 		</Cursor>
 		</Cursor>
 	</File>
 	</File>
-	<File name="lib\ssd1306xled\ssd1306xledtx.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\rtos\rtos.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 		<Cursor>
-			<Cursor1 position="1053" topLine="0" />
+			<Cursor1 position="72" topLine="0" />
 		</Cursor>
 		</Cursor>
 	</File>
 	</File>
-	<File name="inc\main.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\ssd1306xled\ssd1306xledtx.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 		<Cursor>
-			<Cursor1 position="38" topLine="0" />
+			<Cursor1 position="1053" topLine="0" />
 		</Cursor>
 		</Cursor>
 	</File>
 	</File>
-	<File name="lib\ssd1306xled\ssd1306xledtx.c" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="src\sensor.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 		<Cursor>
-			<Cursor1 position="2433" topLine="14" />
+			<Cursor1 position="1465" topLine="13" />
 		</Cursor>
 		</Cursor>
 	</File>
 	</File>
-	<File name="lib\rtos\rtos.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\rtos\rtos.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 		<Cursor>
-			<Cursor1 position="72" topLine="0" />
+			<Cursor1 position="2098" topLine="0" />
 		</Cursor>
 		</Cursor>
 	</File>
 	</File>
-	<File name="lib\ssd1306xled\ssd1306xled.c" open="1" top="1" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\tinyavrlib\num2str.c" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 		<Cursor>
-			<Cursor1 position="5489" topLine="113" />
+			<Cursor1 position="2700" topLine="43" />
 		</Cursor>
 		</Cursor>
 	</File>
 	</File>
-	<File name="src\main.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="inc\i2c.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 		<Cursor>
-			<Cursor1 position="421" topLine="8" />
+			<Cursor1 position="52" topLine="0" />
 		</Cursor>
 		</Cursor>
 	</File>
 	</File>
-	<File name="src\sensor.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="src\i2c.c" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 		<Cursor>
-			<Cursor1 position="1465" topLine="13" />
+			<Cursor1 position="959" topLine="15" />
 		</Cursor>
 		</Cursor>
 	</File>
 	</File>
 </CodeBlocks_layout_file>
 </CodeBlocks_layout_file>

+ 1 - 1
Makefile

@@ -62,7 +62,7 @@ MCU = atmega328p
 #         F_CPU = 16000000
 #         F_CPU = 16000000
 #         F_CPU = 18432000
 #         F_CPU = 18432000
 #         F_CPU = 20000000
 #         F_CPU = 20000000
-F_CPU = 8000000
+F_CPU = 16000000
 
 
 
 
 # Output format. (can be srec, ihex, binary)
 # Output format. (can be srec, ihex, binary)

+ 2 - 0
inc/i2c.h

@@ -1,6 +1,8 @@
 #ifndef _I2C_H_
 #ifndef _I2C_H_
 #define _I2C_H_
 #define _I2C_H_
 
 
+#define F_TWI   400000
+
 /* I2C Status */
 /* I2C Status */
 typedef enum {
 typedef enum {
   I2C_Ret_OK    = 0,
   I2C_Ret_OK    = 0,

+ 1 - 2
inc/main.h

@@ -15,9 +15,8 @@
  * Global defines
  * Global defines
  */
  */
 #ifndef F_CPU
 #ifndef F_CPU
-  #define F_CPU   8000000
+  #define F_CPU   16000000
 #endif
 #endif
-#define F_TWI             400000
 #define TIMER0_HZ         1000
 #define TIMER0_HZ         1000
 #define TIMER0_PRESCALER  64
 #define TIMER0_PRESCALER  64
 #define	TIMER0_CNT        (0x100 - (F_CPU / TIMER0_PRESCALER / TIMER0_HZ))
 #define	TIMER0_CNT        (0x100 - (F_CPU / TIMER0_PRESCALER / TIMER0_HZ))

+ 5 - 0
src/i2c.c

@@ -21,6 +21,11 @@ COPYRIGHT (C) 2008-2009 EXTREME ELECTRONICS INDIA
 volatile uint8_t TWI_WDT;
 volatile uint8_t TWI_WDT;
 
 
 void I2C_Init(void) {
 void I2C_Init(void) {
+  /* TWI / I2C, 400 kHz mode, Prescaler=1
+     ((F_CPU / F_TWI) - 16) / 2
+     ((16000000 / 400000) - 16) / 2 = 12 */
+  TWBR = 12;
+
   //Enable the TWI Module
   //Enable the TWI Module
   TWCR |= (1<<TWEN);
   TWCR |= (1<<TWEN);
 }
 }

+ 2 - 5
src/main.c

@@ -2,6 +2,7 @@
  * Dryer
  * Dryer
  */
  */
 #include "main.h"
 #include "main.h"
+#include "i2c.h"
 #include "sensor.h"
 #include "sensor.h"
 #include "rtos/rtos.h"
 #include "rtos/rtos.h"
 #include "ssd1306xled/font6x8.h"
 #include "ssd1306xled/font6x8.h"
@@ -19,6 +20,7 @@ static void board_Init(void);
 int main(void) {
 int main(void) {
   board_Init();
   board_Init();
   RTOS_Init();
   RTOS_Init();
+  I2C_Init();
   //AHT10_Init();
   //AHT10_Init();
   tdelay_ms(40);
   tdelay_ms(40);
   ssd1306_init();
   ssd1306_init();
@@ -94,11 +96,6 @@ static void board_Init(void) {
   //TCNT2 = 0x00;
   //TCNT2 = 0x00;
   //TIMSK |= _BV(TOIE2);
   //TIMSK |= _BV(TOIE2);
 
 
-  /* TWI / I2C, 400 kHz mode, Prescaler=1
-     ((F_CPU / F_TWI) - 16) / 2
-     ((8000000 / 400000) - 16) / 2 = 2 */
-  TWBR = 2;
-
 #ifdef USE_UART
 #ifdef USE_UART
   /* USART */
   /* USART */
   DDRD |= _BV(PD0); // RX to Input
   DDRD |= _BV(PD0); // RX to Input