View previous topic :: View next topic |
Author |
Message |
ofvy
Joined: 28 Jan 2006 Posts: 42
|
Posted: Wed Nov 24, 2021 2:16 am Post subject: Master Modbus error on ATMega2560 |
|
|
Hi.
I implemented a Modbus Master using an ATMEGA328PB. Serial port 1 is used for debugging and configuration and serial port 2 is used as Modbus port. Works very well.
Now I need to do the same with an ATmega2560, but when I compile the program I get the following error:
Error: 61 Line: 127 Label not found [_SENDCHAR3], in File: C: \ MCS \ BASCAVR2084 \ LIB \ MODBUS.LBX
Does anyone know if it is a bug or if it is necessary to add some additional configuration?
Thank you in advance for your help.
(BASCOM-AVR version : 2.0.8.4 ) |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Wed Nov 24, 2021 10:04 am Post subject: |
|
|
Hi,
Please include code that shows the problem. Without it's not easy to help.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Nov 25, 2021 11:01 am Post subject: |
|
|
you either need to open that COM port so the label gets included. or you need to alter lib.
Code: |
_sendModbusChar:
#IF _XMEGA
;mov r23,r30 ; channel
st -y,r30
Jmp _SENDCHAR
#ELSE
cpi r19,1 ; is it UART0?
brne _sendModbusChar2
Jmp _SendChar0
_sendModbusChar2:
#IF _UARTS>1
cpi r19,2 ; is it UART1?
brne _sendModbusChar3
Jmp _SendChar1
#ENDIF
_sendModbusChar3:
#IF _UARTS>2
cpi r19,3 ; is it UART2
brne _sendModbusChar4 ; must be UART3 then
Jmp _SendChar3
#ENDIF
_sendModbusChar4:
#IF _UARTS>3
Jmp _SendChar4
#ELSE
ret
#ENDIF
#ENDIF
|
as you can see when a processor has multiple uarts there is code to check which uart is used
and _SENDCHARx only exist when that com/uart is used for sending data.
you can also edit the lib and remark using ;
in that case better rename modbus.lib and after edit either include with $LIB or compiler with Lib Manager. _________________ Mark |
|
Back to top |
|
|
ofvy
Joined: 28 Jan 2006 Posts: 42
|
Posted: Fri Nov 26, 2021 6:14 pm Post subject: |
|
|
Hi Ian.
Here is a short version of the code:
Code: | $version 0 , 1 , 204
$regfile = "m328pbdef.dat"
'$regfile = "m2560def.dat"
$crystal = 11059200
$baud = 9600
$baud1 = 115200
$hwstack = 256
$swstack = 256
$framesize = 256
$projecttime = 4
$lib "modbus.lbx"
Const Idslave = 1
' Puerto serial 1
Open "com1:" For Binary As #1
'On Urxc At_ser1
'Enable Urxc
Dir485 Alias Portb.1
Config Print0 = Dir485 , Mode = Set
Config Dir485 = Output
Config Com2 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 1
Open "COM2:" For Binary As #2
Enable Interrupts
Do
Print #1 , Makemodbus(idslave , 4 , 12544 , 12) ' For serial debug
Print #2 , Makemodbus(idslave , 4 , 12544 , 12);
Wait 1
Loop |
When I compile with ATMega 328PB there is no problem.
The program works well in a real application that reads the registers of a solar charger that has a Modbus interface.
If you use the ATmega2560, the error mentioned above is generated.
Thanks in advance for your suggestions. |
|
Back to top |
|
|
ofvy
Joined: 28 Jan 2006 Posts: 42
|
Posted: Fri Nov 26, 2021 6:27 pm Post subject: |
|
|
Hi Mark.
I'm going to test what you suggest, editing the library.
I will comment on the results.
Kind regards.
P.S. Thank you for your support for so long with Bascom. I have been using it for about ten years with good results. |
|
Back to top |
|
|
ofvy
Joined: 28 Jan 2006 Posts: 42
|
Posted: Tue Nov 30, 2021 2:19 am Post subject: |
|
|
I had no luck editing the modbus.lib library.
Maybe someone has some additional ideas.
Thank you in advance for your help |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Tue Nov 30, 2021 5:15 am Post subject: |
|
|
I dont know yet why this happen but know the quick workaround . There is five in the morning here so I dont drink any coffe today yet
If you open the m2560def.dat and mod "uarts" from 4 to 2 then your example code will compile fine but you dont have UART2 and UART3 anymore ofcourse.
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Nov 30, 2021 2:07 pm Post subject: |
|
|
the assumption was that when using a micro with many uarts, they are all used. i know, that is not a good assumption.
the lib could work for just the first usart but in order to make it more flexible, all are supported.
but that also means that the _sendcharX label must be present.
so the most simple way to solve it : add these labels somewhere in your code.
and when you do use the USART later, and the label is included from mcs.lib/lbx you can remove your own label _________________ Mark |
|
Back to top |
|
|
ofvy
Joined: 28 Jan 2006 Posts: 42
|
Posted: Tue Nov 30, 2021 3:47 pm Post subject: |
|
|
Hi Mark.
I need three serial ports in my application, that's why I use the ATMEGA2560.
With your recommendation I added the other ports and now the basic program is compiled.
I am going to implement the complete solution.
Thank you.
Code: | $regfile = "m2560def.dat"
$crystal = 11059200
$baud = 9600
$baud1 = 115200
$hwstack = 256
$swstack = 256
$framesize = 256
$projecttime = 25
$lib "modbus_2560.lbx"
Const Idslave = 1
' Puerto serial 1
Open "com1:" For Binary As #1
'On Urxc At_ser1
'Enable Urxc
Dir485 Alias Portb.1
Config Print0 = Dir485 , Mode = Set
Config Dir485 = Output
Config Com2 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 1
Open "COM2:" For Binary As #2
Open "COM3:" For Binary As #3
Open "COM4:" For Binary As #4
Enable Interrupts
Print #3 , "Dummy3"
Print #4 , "Dummy4"
Do
Print #1 , Makemodbus(idslave , 4 , 12544 , 12) ' For serial debug
Print #2 , Makemodbus(idslave , 4 , 12544 , 12);
Wait 1
Loop |
|
|
Back to top |
|
|
|