Skip to content

Commit

Permalink
Merge pull request #139 from nielsonm236/BME280-Addition3
Browse files Browse the repository at this point in the history
Add BME280 and fixes
  • Loading branch information
nielsonm236 authored Jan 27, 2023
2 parents 50cfb3f + 70f4295 commit 8205416
Show file tree
Hide file tree
Showing 42 changed files with 4,780 additions and 1,648 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

~$twork Module Manual - Code Rev 20221217 1925.doc
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion NetworkModule/.Idea_Groups/Vector_File.grp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Group File Created by IDEA
# Project: <NetworkModule>
# Sat Dec 24 03:36:12 2022
# Wed Jan 25 14:43:22 2023
#
"networkmodule_vector.o"
647 changes: 325 additions & 322 deletions NetworkModule/.Idea_Temp/COBJ.TMP

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions NetworkModule/.Idea_Temp/IDEA.ERR
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- NetworkModule_vector.o
- crts0.sm8
- bme280.o
- ds18b20.o
- enc28j60.o
- gpio.o
Expand All @@ -18,6 +19,7 @@
- libm0.sm8
- NetworkModule_vector.o
- crts0.sm8
- bme280.o
- ds18b20.o
- enc28j60.o
- gpio.o
Expand All @@ -36,6 +38,7 @@
- libm0.sm8
NetworkModule_vector.o:
C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\crts0.sm8:
bme280.o:
ds18b20.o:
enc28j60.o:
gpio.o:
Expand Down
4 changes: 2 additions & 2 deletions NetworkModule/.Idea_Temp/IDEABLD.BAT
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
REM COMMAND FILE BUILT BY IDEA
REM Sat Dec 24 03:36:08 2022
REM Wed Jan 25 14:43:18 2023
REM
cxstm8 -v -l +strict +debug +modsl0 +split +warn "networkmodule_vector.c"
cxstm8 -v -l +strict +debug +modsl0 +split +warn "ds18b20.c" "enc28j60.c" "gpio.c" "httpd.c" "i2c.c" "main.c" "mqtt.c" "mqtt_pal.c" "spi.c" "timer.c" "uart.c" "uip.c" "uip_arp.c" "uip_tcpapphub.c"
cxstm8 -v -l +strict +debug +modsl0 +split +warn "bme280.c" "ds18b20.c" "enc28j60.c" "gpio.c" "httpd.c" "i2c.c" "main.c" "mqtt.c" "mqtt_pal.c" "spi.c" "timer.c" "uart.c" "uip.c" "uip_arp.c" "uip_tcpapphub.c"
clnk -v -sa -o "NetworkModule.sm8" -m "NetworkModule.map" "networkmodule.lkf"
chex -f3 -o "NetworkModule.sx" "NetworkModule.sm8"
clabs "NetworkModule.sm8"
59 changes: 21 additions & 38 deletions NetworkModule/DS18B20.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,31 @@
Copyright 2021 Michael Nielson
*/

// all includes are in main.h
#include "main.h"

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
// #include <stdint.h>
// #include <stdlib.h>
// #include <string.h>
// #include <stdio.h>

#include "iostm8s005.h"
#include "stm8s-005.h"
#include "DS18B20.h"
#include "main.h"
#include "timer.h"
#include "uart.h"
#include "uipopt.h"
// #include "iostm8s005.h"
// #include "stm8s-005.h"
// #include "DS18B20.h"
// #include "timer.h"
// #include "uart.h"
// #include "uipopt.h"


#if DS18B20_SUPPORT == 1

uint8_t DS18B20_scratch_byte[2]; // Array to store scratchpad bytes
// read from DS18B20
uint8_t DS18B20_scratch[5][2]; // Stores the temperature measurement
// for the DS18B20s

extern uint8_t OctetArray[11]; // Used in emb_itoa conversions but
// also repurposed as a temporary
// buffer for transferring data
// between functions.
extern uint8_t OctetArray[14]; // Used in emb_itoa conversions and to
// transfer short strings globally

// Table used for rounding the decimal part of temperatures
static const uint8_t dec_temp[] = {
Expand Down Expand Up @@ -90,13 +92,6 @@ uint8_t FoundROM[5][8]; // Table of ROM codes
// [x][7] = CRC
extern int numROMs; // Count of DS18B20 devices found

// uint8_t new_FoundROM_crc; // Used in calculation of the CRC for
// the FoundROM table. Used to determine
// if a table change has occurred.
// uint8_t old_FoundROM_crc; // Stores the prior FoundROM table CRC.
// extern uint8_t redefine_temp_sensors; // Flag used to signal the need
// to redefine the HA temp sensors
// via Auto Discovery messages


//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -236,7 +231,6 @@ void get_temperature()

void convert_temperature(uint8_t device_num, uint8_t degCorF)
{
//---------------------------------------------------------------------------//
// This function will convert a temperature value stored in the
// DS18B20_scratch array into a string in degrees C or degrees F. The
// function leaves the converted result in the global OctetArray string.
Expand Down Expand Up @@ -578,10 +572,6 @@ void one_wire_low(int wait)

void init_DS18B20(void)
{
// Initialize variables used in DS18B20 operation
// new_FoundROM_crc = 0;
// old_FoundROM_crc = 0;
// redefine_temp_sensors = 0;
// Initialize temperature sensor arrays
memset(&DS18B20_scratch[0][0], 0, 10);
memset(&FoundROM[0][0], 0, 40);
Expand Down Expand Up @@ -633,16 +623,6 @@ void FindDevices(void)
}
}
}
// Add up the crc values for each entry to act as a CRC for the FoundROM
// table
// new_FoundROM_crc = (uint8_t)(FoundROM[0][7] + FoundROM[1][7] + FoundROM[2][7] + FoundROM[3][7] + FoundROM[4][7]);

// if (new_FoundROM_crc != old_FoundROM_crc) {
// Signal the main loop that the temp sensors need to be updated in the
// Browser display and over MQTT
// redefine_temp_sensors = 1;
// old_FoundROM_crc = new_FoundROM_crc;
// }
}


Expand All @@ -655,7 +635,7 @@ uint8_t First(void)
// https://www.maximintegrated.com/en/design/technical-documents/app-notes/1/162.html
//
lastDiscrep = 0; // reset the rom search last discrepancy global
doneFlag = FALSE;
doneFlag = 0; // False
return Next(); // call Next and return its return value
}

Expand Down Expand Up @@ -759,3 +739,6 @@ uint8_t dallas_crc8(uint8_t *data, uint8_t size)
}
return crc;
}


#endif // DS18B20_SUPPORT == 1
39 changes: 19 additions & 20 deletions NetworkModule/Enc28j60.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
*/

/* Modifications 2020 Michael Nielson
/* Modifications 2020-2022 Michael Nielson
* Adapted for STM8S005 processor, ENC28J60 Ethernet Controller,
* Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set.
* Author: Michael Nielson
Expand All @@ -40,16 +40,17 @@
See GNU General Public License at <http://www.gnu.org/licenses/>.
Copyright 2020 Michael Nielson
Copyright 2022 Michael Nielson
*/

#include "Enc28j60.h"
#include "iostm8s005.h"
#include "stm8s-005.h"
#include "uipopt.h"
#include "timer.h"
// All includes are in main.h
#include "main.h"
#include "uart.h"
// #include "Enc28j60.h"
// #include "iostm8s005.h"
// #include "stm8s-005.h"
// #include "uipopt.h"
// #include "timer.h"
// #include "uart.h"

#if DEBUG_SUPPORT != 0
// Variables used to store debug information
Expand All @@ -60,10 +61,8 @@ extern uint8_t RXERIF_counter; // Counts RXERIF errors
extern uint8_t TXERIF_counter; // Counts TXERIF errors
extern uint32_t TRANSMIT_counter; // Counts any transmit
extern uint8_t stored_config_settings; // Config settings stored in EEPROM
extern uint8_t OctetArray[11]; // Used in emb_itoa conversions but
// also repurposed as a temporary
// buffer for transferring data
// between functions.
extern uint8_t OctetArray[14]; // Used in emb_itoa conversions and to
// transfer short strings globally


// SPI Opcodes
Expand Down Expand Up @@ -641,7 +640,7 @@ uint16_t Enc28j60Receive(uint8_t* pBuffer)
if (Enc28j60ReadReg(BANKX_EIR) & 0x01) {

#if DEBUG_SUPPORT != 11
UARTPrintf("Enc28j60Receive OVERFLOW detected\r\n");
// UARTPrintf("Enc28j60Receive OVERFLOW detected\r\n");
#endif // DEBUG_SUPPORT != 11

RXERIF_counter++;
Expand Down Expand Up @@ -687,7 +686,7 @@ UARTPrintf("Enc28j60Receive OVERFLOW detected\r\n");
}
else {
#if DEBUG_SUPPORT != 11
UARTPrintf("Enc28j60Receive MAXFRAME exceeded\r\n");
// UARTPrintf("Enc28j60Receive MAXFRAME exceeded\r\n");
#endif // DEBUG_SUPPORT != 11
}

Expand All @@ -714,12 +713,12 @@ UARTPrintf("Enc28j60Receive MAXFRAME exceeded\r\n");
Enc28j60SetMaskReg(BANKX_ECON2 , (1<<BANKX_ECON2_PKTDEC));

#if DEBUG_SUPPORT != 11
if (nBytes > (ENC28J60_MAXFRAME - 20)) {
UARTPrintf("Enc28j60Received nBytes = ");
emb_itoa(nBytes, OctetArray, 10, 3);
UARTPrintf(OctetArray);
UARTPrintf("\r\n");
}
// if (nBytes > (ENC28J60_MAXFRAME - 20)) {
// UARTPrintf("Enc28j60Received nBytes = ");
// emb_itoa(nBytes, OctetArray, 10, 3);
// UARTPrintf(OctetArray);
// UARTPrintf("\r\n");
// }
#endif // DEBUG_SUPPORT != 11

return nBytes;
Expand Down
5 changes: 3 additions & 2 deletions NetworkModule/Enc28j60.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
*/

/* Modifications 2020 Michael Nielson
/* Modifications 2020-2022 Michael Nielson
* Adapted for STM8S005 processor, ENC28J60 Ethernet Controller,
* Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set.
* Author: Michael Nielson
Expand All @@ -42,11 +42,12 @@
See GNU General Public License at <http://www.gnu.org/licenses/>.
Copyright 2020 Michael Nielson
Copyright 2022 Michael Nielson
*/




#ifndef ENC28J60_H_
#define ENC28J60_H_

Expand Down
Loading

0 comments on commit 8205416

Please sign in to comment.