CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Timeout modbus
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Mvedovetto



Joined: 17 Aug 2007
Posts: 38

View user's profile Send private message Send e-mail

PostPosted: Thu Sep 19, 2024 9:35 am     Reply with quote

I want to test it. I prefer to spend some time to test before redesign and manufacture PCB board again.

Preprocessor directory #fuses NOCLKOUT, sets bit #8 of CONFIG1 register?
Ttelmah



Joined: 11 Mar 2010
Posts: 19529

View user's profile Send private message

PostPosted: Thu Sep 19, 2024 11:42 am     Reply with quote

Yes, but that is the default, unless your clock setup is one that enables
the clock out.
You don't show us your clock setup, so we cannot tell how things will actually
be done by the compiler.
Also if that is enabled, you would see the clock out when you run the chip
without this serial. Old thing, always check your chip is working and working
how you expect before doing complex things like Modbus....
Mvedovetto



Joined: 17 Aug 2007
Posts: 38

View user's profile Send private message Send e-mail

PostPosted: Thu Sep 26, 2024 12:12 pm     Reply with quote

Quote:
Yes, but that is the default, unless your clock setup is one that enables
the clock out.
You don't show us your clock setup, so we cannot tell how things will actually
be done by the compiler.

I apologize: did not read you reply!

Here it is clock setup

Code:

#fuses NOWDT //watchdog non gestito
#fuses NOPUT //nessun mantenimento in reset dopo il POR (power on reset)
#fuses BROWNOUT //non abilita il reset quando la tensione di alimentazione scende sotto un determinato livello
#fuses NOLVP// programmazione low voltage non abilitata
#fuses NOMCLR//funzione MCLR non abilitata: MCLR weak pull-up e MCLR pin come digital I/O
#fuses NOCLKOUT

#use delay(internal=32Mhz)


Anyway do not run: seems doesn't receive in pin RX of UART1 mapped in RA4.

Once remapped UART1 in C1- C0 Modbus RTU Master runs without errors with modbus slave simulator.

Moreover, Microchip support confirms he successfully tried UART communication on PortA pin: (I hope he used RA4 for RX and RA5 for TX) and suggest to use XC8 Compiler.

I have NO time nor adequate skills to test XC8: I'll write to CCS support and in the meantime I modify PCB.

Quote:
Old thing, always check your chip is working and working
how you expect before doing complex things like Modbus....

Mistakes teach, which is why I always test the circuit board by checking the ports with the oscilloscope, pulse generator, multimeter and checking the shapes of the signals, unwanted “noise” and so on. This time I also generated a pulse signal from B7 and in turn connected it to the interface pins and matched it to the input of RC7 via software, checking with the oscilloscope channel that the signals match.
Mvedovetto



Joined: 17 Aug 2007
Posts: 38

View user's profile Send private message Send e-mail

PostPosted: Sun Sep 29, 2024 9:41 am     Reply with quote

It works! Both CCS support and Microchip support confirmed that the UART is remappable to any pin. So I asked again for support to CCS (microchip advised me to use XC8 compiler).

I used a modified ex_modbus_master.c provided by CCS support and changed the PIC16F17146 micro to be sure to start from a clean situation, then tested with ModRSim2 using also the function that adds noise to the communication and the result is that everything works fine!

By the way, before changing the micro I tested if any contact could occur, to avoid hardware errors, since it seemed not to receive info from the slave (anyway I had tested the PCB assembly before developing the application firmware): no contact nor cross connection.

If you find exceptions in the results, it is purposely caused by the simulator notifying me that it introduced noise into the communication to simulate a communication error.



    ...
    5. Turn coil 6 on.
    6. Write 0x4444 to register 0x03
    7. Set 8 coils using 0x50 as mask
    8. Set 2 registers to 0x1111, 0x2222
    9. Send unknown command

    Input Registers:
    Data: 12 34 56 78 9A BC DE F0 00 00 00 00 00 00 00 00


    Pick command to send
    1. Read all coils.
    2. Read all inputs.
    3. Read all holding registers.
    4. Read all input registers.
    5. Turn coil 6 on.
    6. Write 0x4444 to register 0x03
    7. Set 8 coils using 0x50 as mask
    8. Set 2 registers to 0x1111, 0x2222
    9. Send unknown command

    Input Registers:
    <-**Exception 0C**->


    Pick command to send
    1. Read all coils.
    2. Read all inputs.
    3. Read all holding registers.
    4. Read all input registers.
    5. Turn coil 6 on.
    6. Write 0x4444 to register 0x03
    7. Set 8 coils using 0x50 as mask
    8. Set 2 registers to 0x1111, 0x2222
    9. Send unknown command

    Input Registers:
    Data: 12 34 56 78 9A BC DE F0 00 00 00 00 00 00 00 00


    Pick command to send
    1. Read all coils.
    2. Read all inputs.
    ...


code is the same of ex_modbus_master except for specific settings:
Code:

#include <16F17146.h>
#fuses NOWDT
#use delay(internal=32Mhz)
#define TX1_RTU_OM3_TOK    PIN_A4
#define RX1_RTU_DE         PIN_A5
#define TX2_MIF            PIN_C0
#define RX2_MIF            PIN_C1
#pin_select U1TX=TX1_RTU_OM3_TOK
#pin_select U1RX=RX1_RTU_DE
#pin_select U2TX=TX2_MIF
#pin_select U2RX=RX2_MIF
#use rs232 (UART2,stream=MMIF,baud=9600,bits=8,parity=N, stop=1,errors)
#define DEBUG_MSG(msg)        fprintf(MMIF, msg)
#define DEBUG_DATA(msg,data)  fprintf(MMIF, msg, data)

#define MODBUS_SERIAL_BAUD       9600
#define MODBUS_SERIAL_RX_PIN     RX1_RTU_DE
#define MODBUS_SERIAL_TX_PIN     TX1_RTU_OM3_TOK
#define MODBUS_PARITY            "NONE"
#define MODBUS_SERIAL_STOP_BITS  1
#define MODBUS_SERIAL_TIMEOUT    300000
#define MODBUS_TIMER_USED        MODBUS_TIMER_T2

#include <modbus.c>

#define MODBUS_SLAVE_ADDRESS 0x01
...


Upon CCS info support, the timeout was modified to consider any delays introduced by the software simulator.

So I can confirm that pins are remappable! Now I test the solution with the application software to complete test.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group