View previous topic :: View next topic |
Author |
Message |
Climber
Joined: 05 Jun 2012 Posts: 15
|
Posted: Tue Feb 02, 2016 9:08 pm Post subject: Serial Input with Atemega 128 |
|
|
Hi
the following code example show a test peace for serial code with the Atemega 128.
The Atemega 128 has 2 uarts so the configuration is not so easy as until now.
But i did it The serial output work !
Now i have 2 questions.
1.) Input #2 don't work
what must i do to receive serial datas in this case?
I am sure that the sender works right, with a other system i receive datas.
2.) Actually i don't need com1
But it is not possible to work only with com2.
If i only config and open com2 i get a error from the compiler "External routine not found"
This is not really bad for me, but i don't understand it.
My important problem is 1.)
Thanks a lot for your help!
Code: |
Config Com1 = 38400 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Com2 = 38400 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "com1:" For Binary As #1
Open "com2:" For Binary As #2
Do 'This work fine
Print #1 , "Send from Port 1"
Wait 2
Print #2 , "Send from Port 2"
Wait 2
Input #2, Text 'This dont't work
Cls
LCD Text
Loop
Close #2
Close #1
|
[/code]
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Feb 02, 2016 10:17 pm Post subject: |
|
|
- always check the samples\CHIPS folder. it contains simple samples for most processors. in this case there is m128.bas which show communication for both serial ports.
- when you only need COM2, you can set up only com2.
here is modded sample :
Code: | '-----------------------------------------------------------------------------------------
'name :
'copyright : (c) 1995-2015, MCS Electronics
'purpose : test for M128 support in M128 mode
'micro : Mega128
'suited for demo : yes
'commercial addon needed : no
'-----------------------------------------------------------------------------------------
$regfile = "m128def.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$baud1 = 19200
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
'By default the M128 has the M103 compatibility fuse set. Set the fuse to M128
'It also runs on a 1 MHz internal oscillator by default
'Set the internal osc to 4 MHz for this example DCBA=1100
'use the m128def.dat file when you wanto to use the M128 in M128 mode
'The M128 mode will use memory from $60-$9F for the extended registers
'Since some ports are located in extended registers it means that some statements
'will not work on these ports. Especially statements that will set or reset a bit
'in a register. You can set any bit yourself with the PORTF.1=1 statement for example
'But the I2C routines use ASM instructions to set the bit of a port. These ASM instructions may
'only be used on port registers. PORTF and PORTG will not work with I2C.
'The M128 has an extended UART.
'when CONFIG COMx is not used, the default N,8,1 will be used
'Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Com2 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'try the second hardware UART
Open "com2:" For Binary As #1
Dim B As Byte
Do
Print #1 , "UART1"
B = Inkey(#1)
If B = 27 Then
Input #1 , "test serial port 0" , B
Print #1 , B
End If
Waitms 500
Loop
Close #1
End |
_________________ Mark |
|
Back to top |
|
|
Climber
Joined: 05 Jun 2012 Posts: 15
|
Posted: Wed Feb 03, 2016 6:09 am Post subject: |
|
|
Hi Mark,
with your sample code it works. I don't see the difference to my code but i think i find it out later.
Another question.
I use Bascom now since 5 years and i'm very pleased with it. I payed only once for this product.
Now i you would like to make a small donation. I think after 5 years this is o.k.
How can i make this ?
Many greatings:
Climber |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Feb 03, 2016 10:39 am Post subject: |
|
|
you did not post complete code so it is hard to tell. at first glance it should work. only trap with M128 is the M103 compatibility fuse bit. but that was not the problem in this case.
good to hear you like the free updates. you can always buy one of the add on libs, or send a donation to paypal@mcselec.com .
But to hear that the software helped you is enough reward. _________________ Mark |
|
Back to top |
|
|
|
|
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 You cannot attach files in this forum You cannot download files in this forum
|
|