diff --git a/main.c b/main.c
index 7d192b5..9c90edb 100644
--- a/main.c
+++ b/main.c
@@ -50,12 +50,8 @@
/*
Main application
*/
-void resetTMR0(void);
-void endFrame(void);
-
-uint8_t nRxByte = 0;
-extern uint8_t rx_buf[256];
+extern uint16_t input_registers[2];
void main(void)
{
// Initialize the device
@@ -84,13 +80,13 @@ void main(void)
// Disable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptDisable();
uint16_t foo = 512;
- EUSART1_SetRxInterruptHandler(resetTMR0);
- TMR0_SetInterruptHandler(endFrame);
+
while (1)
{
foo = ++foo%1023;
EPWM1_LoadDutyValue(foo);
- uint16_t valueV = measure_voltage();
+ input_registers[0] = measure_voltage();
+ uint16_t valueV = input_registers[0];
uint16_t valueI = measure_current(offsetCurrent);
char msg[MAX_COL+1];
@@ -106,20 +102,6 @@ void main(void)
}
-void resetTMR0(void){
- rx_buf[nRxByte++] = RCREG1;
- TMR0_Reload();
- TMR0_StartTimer();
-}
-
-void endFrame(void){
- INTCONbits.TMR0IF = 0;
- nRxByte = 0;
- TMR0_StopTimer();
- modbus_analyse_and_answer();
-
- // TODO
-}
/**
End of File
*/
\ No newline at end of file
diff --git a/mcc_generated_files/eusart1.c b/mcc_generated_files/eusart1.c
index 5700d00..17c5184 100644
--- a/mcc_generated_files/eusart1.c
+++ b/mcc_generated_files/eusart1.c
@@ -93,8 +93,8 @@ void EUSART1_Initialize(void)
// SPEN enabled; RX9 9-bit; CREN enabled; ADDEN disabled; SREN disabled;
RCSTA1 = 0xD0;
- // TX9 9-bit; TX9D 0; SENDB sync_break_complete; TXEN enabled; SYNC asynchronous; BRGH hi_speed; CSRC master_mode;
- TXSTA1 = 0xE4;
+ // TX9 9-bit; TX9D 1; SENDB sync_break_complete; TXEN enabled; SYNC asynchronous; BRGH hi_speed; CSRC master_mode;
+ TXSTA1 = 0xE5;
//
SPBRG1 = 0x8A;
diff --git a/mcc_generated_files/tmr0.c b/mcc_generated_files/tmr0.c
index d2d9627..47f3b28 100644
--- a/mcc_generated_files/tmr0.c
+++ b/mcc_generated_files/tmr0.c
@@ -90,8 +90,8 @@ void TMR0_Initialize(void)
// Set Default Interrupt Handler
TMR0_SetInterruptHandler(TMR0_DefaultInterruptHandler);
- // T0PS 1:2; T08BIT 16-bit; T0SE Increment_hi_lo; T0CS FOSC/4; TMR0ON enabled; PSA not_assigned;
- T0CON = 0x98;
+ // T0PS 1:2; T08BIT 16-bit; T0SE Increment_hi_lo; T0CS FOSC/4; TMR0ON disabled; PSA not_assigned;
+ T0CON = 0x18;
}
void TMR0_StartTimer(void)
diff --git a/modbus.c b/modbus.c
index e1b789c..a9ed127 100644
--- a/modbus.c
+++ b/modbus.c
@@ -43,15 +43,17 @@ void modbus_timer(void)
extern uint16_t measure_voltage();
uint8_t modbus_analyse_and_answer(void) {
// TODO -> complete the modbus analyse and answer
+ uint8_t length = 0;
if(rx_buf[0] == modbusAddress){
- tx_buf[0] = rx_buf[0];
- tx_buf[1] = rx_buf[1];
+ tx_buf[0] = rx_buf[0]; // Adress
+ tx_buf[1] = rx_buf[1]; // Function
switch(rx_buf[1]){
case READ_INPUT_REGISTERS:
- tx_buf[2] = 2;
- tx_buf[4] = input_registers[0];
- tx_buf[3] = input_registers[0]>>8;
+ tx_buf[2] = 2; // Data length
+ tx_buf[4] = input_registers[0]; // LSB Data
+ tx_buf[3] = input_registers[0]>>8; // MSB Data
+ length = 5;
// todo choose register
break;
case READ_HOLDING_REGISTERS:
@@ -66,8 +68,7 @@ uint8_t modbus_analyse_and_answer(void) {
}
rx_buf[0] = 0;
-
- //
+ modbus_send(length);
}
@@ -80,10 +81,11 @@ void modbus_char_recvd(void)
void modbus_send(uint8_t length)
{
+
uint16_t temp16;
uint8_t i;
- // TODO -> complete modbus RCR calculation
+ // TODO -> complete modbus crc calculation
length += 2; // add 2 CRC bytes for total size
// For all the bytes to be transmitted
diff --git a/modbus.h b/modbus.h
index e1feb9c..2c06fd2 100644
--- a/modbus.h
+++ b/modbus.h
@@ -45,10 +45,10 @@ void modbus_send(uint8_t length);
* This function will be called every time a character has been received on the
* Modbus serial port. It is called from the interrupt hander.
*
- * @param c : the received char
+ * @param c : the received char // removed !
* @see interrupts.c.
*/
-void modbus_char_recvd(uint8_t c);
+void modbus_char_recvd(void);
/**
* Modbus timer finished. This function is called by the interrupt handler
diff --git a/nbproject/Makefile-genesis.properties b/nbproject/Makefile-genesis.properties
index 2dac5f0..58b7953 100644
--- a/nbproject/Makefile-genesis.properties
+++ b/nbproject/Makefile-genesis.properties
@@ -1,11 +1,11 @@
#
-#Thu Mar 09 15:57:40 CET 2023
+#Fri Mar 10 16:03:22 CET 2023
default.languagetoolchain.version=2.40
default.Pack.dfplocation=C\:\\Program Files\\Microchip\\MPLABX\\v6.00\\packs\\Microchip\\PIC18F-J_DFP\\1.5.44
conf.ids=default
default.languagetoolchain.dir=C\:\\Program Files\\Microchip\\xc8\\v2.40\\bin
host.id=3awj-afwq-rl
-configurations-xml=5e78976b44c48e5125d650f70012f653
+configurations-xml=fddef5f935cc83784d98c896c2327263
default.com-microchip-mplab-mdbcore-snap-SnapToolImpl.md5=eaa336cefb7fc46db8b50b7b2b6e54ca
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=6e02ca5e9f5042ffd365b42ab82d3a9b
user-defined-mime-resolver-xml=none
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index f6809b7..8717c5e 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -188,7 +188,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -210,7 +259,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/nbproject/private/configurations.xml b/nbproject/private/configurations.xml
index 20b286a..5a22fab 100644
--- a/nbproject/private/configurations.xml
+++ b/nbproject/private/configurations.xml
@@ -4,7 +4,7 @@
0
- :=MPLABComm-USB-Microchip:=<vid>04D8:=<pid>9018:=<rev>0100:=<man>Microchip Technology Incorporated:=<prod>MPLAB Snap ICD:=<sn>BUR190971772:=<drv>x:=<xpt>b:=end
+ :=MPLABComm-USB-Microchip:=<vid>04D8:=<pid>9018:=<rev>0100:=<man>Microchip Technology Incorporated:=<prod>MPLAB Snap ICD:=<sn>BUR190971815:=<drv>x:=<xpt>b:=end
C:\Program Files\Microchip\xc8\v2.40\bin
place holder 1
diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml
index 2777a27..5e6973e 100644
--- a/nbproject/private/private.xml
+++ b/nbproject/private/private.xml
@@ -3,15 +3,10 @@
- file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/modbus.c
- file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/measure.c
- file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/modbus.h
- file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/main.c
- file:/C:/Program%20Files/Microchip/xc8/v2.40/pic/sources/c99/common/lwmod.c
- file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/mcc_generated_files/interrupt_manager.c
- file:/C:/Program%20Files/Microchip/xc8/v2.40/pic/sources/c99/common/aomod.c
- file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/mcc_generated_files/tmr0.c
- file:/C:/Users/remi/Downloads/MCU/solar_panel/solar_panel.X/mcc_generated_files/eusart1.c
+ file:/C:/Users/remi/MPLABXProjects/solar_panel/mcc_generated_files/interrupt_manager.c
+ file:/C:/Users/remi/MPLABXProjects/solar_panel/main.c
+ file:/C:/Users/remi/MPLABXProjects/solar_panel/modbus.c
+ file:/C:/Users/remi/MPLABXProjects/solar_panel/mcc_generated_files/tmr0.c
diff --git a/solar_panel.mc3 b/solar_panel.mc3
index 0787f8a..77b8116 100644
--- a/solar_panel.mc3
+++ b/solar_panel.mc3
@@ -1004,7 +1004,7 @@
- 228
+ 229
@@ -1124,7 +1124,7 @@
- 0
+ 1
@@ -5648,7 +5648,7 @@
- enabled
+ disabled
@@ -5724,7 +5724,7 @@
- 152
+ 24
@@ -5748,7 +5748,7 @@
- enabled
+ disabled
@@ -6000,25 +6000,25 @@
mcc_generated_files\tmr2.h
9c49623fe191eb686818b525571464bbc0f83e271367728272f8bce53b917f55
-
- mcc_generated_files\tmr2.c
- 05c23c08bae910023f51fd801fa4b4107358a34dbad1624e66d9a30249d1fe86
-
mcc_generated_files\pin_manager.h
87e93cc6f9494828e660861178e9a299efbe16d73a441d92e3dca2a1cf6d54ed
+
+ mcc_generated_files\tmr2.c
+ 05c23c08bae910023f51fd801fa4b4107358a34dbad1624e66d9a30249d1fe86
+
mcc_generated_files\adc.h
58eb4471903133ed806f7edbfce9c3cc4e0af3536917c8f81ad1cbdb72d919fc
- mcc_generated_files\epwm1.h
- e1dacec839b43c4ec99f1710c3a7872ce32d2ea6dfe3856eb466e690b7ea75c9
+ mcc_generated_files\tmr0.c
+ 5999b6142463be670db096db3ffefc4be674ac36a27ce3d5bc69c9811eb5c55f
- mcc_generated_files\tmr0.c
- f8a9d57b93e4810bdf2401ef043ce48c9d645ba81f2241dee96977286f6fb164
+ mcc_generated_files\epwm1.h
+ e1dacec839b43c4ec99f1710c3a7872ce32d2ea6dfe3856eb466e690b7ea75c9
mcc_generated_files\pin_manager.c
@@ -6042,7 +6042,7 @@
mcc_generated_files\eusart1.c
- d8ed730bd093892491a853d1821faa71f3a66365e71b5728f5d34612524be6ec
+ 4b28289ec5a9f1dd41eb4000a98bdf15a60c73701c716add6c562a154a431809
\ No newline at end of file