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 1, 2  Next
 
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

Timeout modbus
PostPosted: Sun Sep 15, 2024 5:38 pm     Reply with quote

I have, with kind support of this forum, code running for 16F18424 as MASTER RTU using CCS modbus library and tested with ModRSsim2 and at least I have had no problem.

Now I'm porting to PIC 16F17146 and always occurs exception 12 TIMEOUT each time I call a modbus function (I need just modbus_write_muiltiple_registers and modbus_read_multiple registers).

Warnings are present after compilation with release 5.118 of PCM:

Warning#216 Interrupts disabled during call to prevent re-entrancy: (modbus_calc_crc):
Warning#216 Interrupts disabled during call to prevent re-entrancy: (modbus_enable_timeout):

and an info: Info#300 More info: Timer 2 tick time is 128,00 us:

I'm using MPLAB X IDE 6.20

Settings are
Code:

//All settings are default but
#define MODBUS_SERIAL_BAUD 9600                             //9600 default
#define MODBUS_SERIAL_RX_PIN  RX1_RTU_DE             //data receive pin
#define MODBUS_SERIAL_TX_PIN  TX1_RTU_OM3_TOK   //data transmit pin
#define MODBUS_PARITY "NONE"                                  //nessuna parità
#define MODBUS_SERIAL_STOP_BITS  1                       //1 bit di stop
#define MODBUS_SERIAL_TIMEOUT 10000                     //in us for RTU
#define MODBUS_TIMER_USED 15                                 // usa timer T2 invece del T1 come default


after init variables, modbus, put a write command and insert in values also comm result

Code:

 do {
        dummy=make8(STATO_EWJ[1],0);
        STATO_EWJ[1]=make16(comm,dummy);
//        int8       address            Slave Address
//        int16      start_address      Address to start at
//        int16      quantity           Amount of 16 bit registers to write to
//        int16*     values             A pointer to an array holding the data to write

         comm=modbus_write_multiple_registers(MODBUS_SLAVE_ADDRESS,0x02,0x02,SEWJ);
         delay_ms(500);

    } while (comm!=0);


program does not quit from while loop because comm=0x0C (=TIMEOUT). The same happens if I try to read.

Modbus Simulator server is set to 1ms Responsiveness and values are correctly loaded in register, including exception value.

Whats wrong?

Thank you for any kind of support!

Ciao

Marco Vedovetto
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Mon Sep 16, 2024 1:14 am     Reply with quote

The warnings are just warnings. They are happening because these two
functions are called both inside the interrupt and outside. Because the
PIC does not have a variable stack, re-entrancy is not allowed, so when
functions are called like this the compiler ensures that the interrupt
cannot happen while the code for the function outside the interrupt is
running. It'll just delay interrupt servicing a few uSec.

Now problem is we don't have enough to really know what is going on.
What clock speed are you running?.
What are RX1_RTU_DE and TX1_RTU_OM3_TOK defined as?.

However I can guess what may be happening. This chip is a PPS chip.
As such, you need to do #PIN_SELECT setups for the UART pins. Unless
you do this, the UART will be configured as a software UART, and the
receive interrupt will not work.
Result timeout......
Mvedovetto



Joined: 17 Aug 2007
Posts: 38

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

PostPosted: Mon Sep 16, 2024 3:14 am     Reply with quote

Thank you for reply, Ttelmah!

You're quite right! I have had great teachers in this forum and I tried to learn lessons Smile so I mapped pins accordling to pic16f17146.h

Quote:
Now problem is we don't have enough to really know what is going on.
What clock speed are you running?.
What are RX1_RTU_DE and TX1_RTU_OM3_TOK defined as?.


Code:

#use delay(internal=32Mhz)

#define RX1_RTU_DE PIN_A5
#define TX1_RTU_OM3_TOK PIN_A4


Quote:
However I can guess what may be happening. This chip is a PPS chip.
As such, you need to do #PIN_SELECT setups for the UART pins. Unless
you do this, the UART will be configured as a software UART, and the
receive interrupt will not work.



Code:

#use delay(internal=32Mhz)

#pin_select U1TX=TX1_RTU_OM3_TOK
#pin_select U1RX=RX1_RTU_DE



Quote:
Result timeout......


If I understand your question, exception is timeout because I send exception as value in data register and I found 0x0C.


Because I have a Modbus simulator ModRSsim2 on Windows 10 PC and use an optoisolated FTDI 232 - USB interface, perhaps I could define MODBUS_SERIAL_INT_SOURCE as INT_EXT instead of default, INT_RDA?

Final application has to communicate via modbus RTU with an embedded system that implements NETWORK stack for ETHERNET/IP protocol, so probably I'll have no problem. But I know also that Murphy is everywhere

Marco
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Mon Sep 16, 2024 5:02 am     Reply with quote

No, using INT_EXT, is for when you wire the receive data line to the INT_EXT
pin and use software serial.

Your problem is that PPS on your chip does not allow the serial to be connected
to the pins you are trying to use. On 20pin chips, the selections are limited
to PortB and PortC, for the serial. Table 18-1 in the data sheet.
Mvedovetto



Joined: 17 Aug 2007
Posts: 38

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

PostPosted: Mon Sep 16, 2024 5:31 am     Reply with quote

This is 16F17146.h section for PIN_SELECT: it seems that PIN_A5 and PIN_A4 are allowed

Code:
////////////////////////////////////////////////////////////////// PIN_SELECT
// #pin_select function=pin
// Valid Pins:
//    PIN_A0,PIN_A1,PIN_A2,PIN_A3,PIN_A4,PIN_A5,PIN_B4,PIN_B5,PIN_B6,PIN_B7,
//    PIN_C0,PIN_C1,PIN_C2,PIN_C3,PIN_C4,PIN_C5,PIN_C6,PIN_C7
// Input Functions:
//    INT0,T0CK,T1CK,T1G,T3CK,T3G,T2CK,T4CK,CCP1,CCP2,PWMIN0,PWMIN1,PWM1RESET,
//    PWM2RESET,CWG1IN,CLCIN0,CLCIN1,CLCIN2,CLCIN3,U1CK,U1RX,U2CK,U2RX,SCK1IN,
//    SCL1IN,SDI1,SDA1IN,SS1IN,SCK2IN,SCL2IN,SDI2,SDA2IN,SS2IN,ADCACT,T0CKI,
//    T1CKI,T3CKI,T2CKI,T4CKI,CCP1IN,CCP2IN,CK1,RX1,CK2,RX2
// Output Functions:
//    NULL,CLC1OUT,CLC2OUT,CLC3OUT,CLC4OUT,CWG1OUTA,CWG1OUTB,CWG1OUTC,CWG1OUTD,
//    CCP1OUT,CCP2OUT,PWM1S1P1,PWM1S1P2,PWM2S1P1,PWM2S1P2,U1TX,U1DT,U2TX,U2DT,
//    C1OUT,C2OUT,SCK1OUT,SCL1OUT,SDO1,SDA1OUT,SCK2OUT,SCL2OUT,SDO2,SDA2OUT,
//    T0OUT,NCO1OUT,CLKROUT,ADGRDA,ADGRDB,SCK1,SCL1,SDA1,SCK2,SCL2,SDA2,TMR0OUT,
//    NCO1
//


On datasheet I did not found that remap serial function to PORT_A is not possible moreover pin allocation table maps at page 15 doesn't report any warning for serial port.

I know that limitation is for chips with more than 28 pins, this is why I decided to freely assign that pins. But sure you're more skilled than me, so I'll try to assign pin to Port B.
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Mon Sep 16, 2024 5:49 am     Reply with quote

The point is the A pins are usable for _some_ functions, but not the serial.
Timer2 input, Timer0/1 clock etc all work..
They incorrectly say this applies only to 28pin devices, but this family
does not have any 28pin devices. It applies to any chip that has three
ports used for the pins. The 18 and 14 pin devices only have PortA and PortC.
As soon as PortB is added this problem appears. So 20pin devices.
It'll only accept 001 and 010 for the port selection for this function.
It is very poorly described in the data sheet I'm afraid. Sad
Mvedovetto



Joined: 17 Aug 2007
Posts: 38

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

PostPosted: Mon Sep 16, 2024 7:31 am     Reply with quote

Ok, I tried. Success: no more timeout error!!!!

I have to redesign PCB Evil or Very Mad Evil or Very Mad Evil or Very Mad

I'll send a claim to Microchip even if I'm certain that will be meaningless.

Thank you for your support, Ttelmah (I always forget your name Razz )

Marco
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Tue Sep 17, 2024 1:13 am     Reply with quote

It is in the data sheet, just very badly expressed, and 'wrong' on the number
of pins involved.
I almost wonder if the sheets are being generated by an AI now. The errors
are fairly typical of their work....
Artificial intelligence = real stupidity.
I think you should point this out to them and just say that because of this
you have had to redesign a board, and suggesting they correct the sheet.
You have a very good chance that they might offer a little 'goodwill' gesture
in a situation like this (some free chips is common). I have had this.
Mvedovetto



Joined: 17 Aug 2007
Posts: 38

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

PostPosted: Tue Sep 17, 2024 4:26 am     Reply with quote

I have read data sheet, but It was really difficult understand that port_A can't map serial peripheral. Honestly I don't clearly understand yet. So I'll notice this lack information to Microchip.

By the way:

Quote:
Artificial intelligence = real stupidity


is really great!

Thank you again Ttelmah!

Marco
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Sep 17, 2024 5:40 am     Reply with quote

I agree the 'newer' PICs are far more complicated than the quartz windowed I ones I used to program !

Just because a PIC has PPS doesn't mean that every pin can be used for every internal peripheral.

Have a look at the 'pin allocation table'. it's the chart that shows all the pins and their uses. When you look at the chart, you'll see that ALL of the PORTA pins have a '---' in the EUART column. That means that pin cannot be used for the serial port.

If possible, consider using the 'biggest' PIC for the 'family'. That PIC might cost $1 more and take up a little more PCB space BUT you gain more memories, more peripherals AND it'll be easier to add more 'stuff' that the client decides he needs.
Mvedovetto



Joined: 17 Aug 2007
Posts: 38

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

PostPosted: Tue Sep 17, 2024 6:23 am     Reply with quote

Quote:
Have a look at the 'pin allocation table'. it's the chart that shows all the pins and their uses. When you look at the chart, you'll see that ALL of the PORTA pins have a '---' in the EUART column. That means that pin cannot be used for the serial port.

I'm not dealing about complexity of programming and configure a PIC (I used windowed PIC too), but table 3-2. 20-Pin Allocation Table of PIC16F17126-46 has "---" in EUSART column for ALL pin of port A, RB4, RB6, RC2, RC3, RC4, RC5, RC6, RC7 pins.

The peripheral EUSART at note 1 (related to RX1, RX2...) says "This is a PPS remappable input signal. The input function may be moved from the default location shown to any PORTx pin".

IMHO because words are not meaningless, it's difficult to understand that EUSART peripherals cannot be assigned to portA pins.

I'm using PIC16F17146 because I need 2 hardware UART. Program memory and pinning are enough for me. I just assigned wrong pin because there are no clearly exposed informations for THIS 20pin chip. I used also 44pin chips and recognized forbidden assignments: no errors!
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Tue Sep 17, 2024 10:14 am     Reply with quote

Jay, many of the previous PIC's had a simple table saying what devices
could connect where. This one though has the data in a complete mess.
It says that the limitation on port accesses only applies to the 28pin versions
(there are none!...). Then doesn't say what ports can be used, but only
gives the binary patterns allowed for the port selection. This you have to
look up in another table elsewhere in the data sheet. I went through this
a few months ago when trying these chips, and swore at MicroChip several
times. I only knew abut it because I had worked it out for myself.
On a scale of 1 to 10, I have to give this part of the data sheet a negative
score. Sad
The limitation applies to the 20pin chips unfortunately.
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Sep 17, 2024 11:19 am     Reply with quote

sounds like the datasheet was AI generated !
sigh... can I go back to using 16C84s now !!!!!!!
Mvedovetto



Joined: 17 Aug 2007
Posts: 38

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

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

Hi all,
this is answer of Microchip support

Quote:
Hi Marco,

I am not very experienced with the CCS compiler but I have tested the configuration you mentioned and was able to remap the EUSART pins to RA4 and RA5 without any errors using the XC8 latest version compiler. The only thing you need to consider is that RA4 and RA5 are the default pins for the external oscillator (OSC1 OSC2) so you cannot use them if the internal oscillator is not selected. Also RA4 is the CLKOUT pin which is default enabled in the configuration bits. This functionality needs to be disabled in order to use this pin.

If you can verify that these functionalities are disabled (CLKOUT disabled and HFINTOSC enabled) there should be no issue using these pins for other purposes. If the issue still persists this might be a limitation of the CCS compiler, for which however I cannot advise.


I'm using internal oscillator so I wanti to check out if CCS disabled CLKOUT when #PIN_SELECT assignment to RA4.

I'll check soon in .lst
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

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

I suspect the person who responded hadn't actually tried it. Just tested that
it programs. It does program, it just does not work. Sad
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 1, 2  Next
Page 1 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