You are calling "wait 3" inside your ISR (Interrupt Service Routine).
While processing an ISR the global interrupt is disabled. When the ISR takes longer as the timer overflow, the interrupt flag is set, but the ISR is not called (aka pending interrupt). After finishing the ISR the controller checks the interrupt flags and processes the pending interrupt, if nessesary.
If the interrupt would not be disabled the HW stack would overflow very easy.
It is a wise practice to keep the processing time of an ISR shorter than a new interrupt can occur.
↧
BASCOM-AVR Old versions : timer overflow and wait statement confuse me!? : REPLY
↧
Share your working BASCOM-AVR code here : Arduino Mega W5100 ethernetshield with SD-card : REPLY
Nice!
Thanks for this sample, it is very helpful
Bojan
↧
↧
BASCOM-AVR : DCF77 time with big characters : NEWTOPIC
hay all.
what I will is the (dcf_sec)time to view this in custom fonts
but how to?
I have now...
Set_font Glcdvet_font
Lcdtext Time$ , 61 , 13 , Inverted , Rotate_0 >>> this will not view the (dcf_sec) time but the Time$
Locate 3 , 11
Lcd Time(dcf_sec) ; " " >>> this will view the (dcf time) but not in custom fonts
Locate 7 , 11
Lcd Date(dcf_day) ; " "
Lcd ; Dow ; " " ; _day ; " " ; Mnd ; " 20" ; _year >>> the same of the date
help please
[b:bcf8768609][color=red:bcf8768609](BASCOM-AVR version : 2.0.7.6 )[/b:bcf8768609][/color:bcf8768609]
↧
BASCOM-AVR Old versions : timer overflow and wait statement confuse me!? : REPLY
thanks a lot laborratte
i understand it. now i change my code as below and it work nice.
other question! what is happen when hardware stack become overflow? processing stopped or reset occur?
[code:1:62feec78da]
$regfile = "m16def.dat"
$crystal = 7372800
$hwstack = 60
$swstack = 60
$framesize = 60
$baud = 115200
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Configurations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Config Lcd = 20 * 4
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Porta.7 , Rs = Porta.6
Config Timer1 = Timer , Prescale = 1024
Stop Timer1
Enable Timer1
On Ovf1 1second
Enable Interrupts
'~~~~~~~~~~~ Variable
Dim A As Word
Dim B As Word
Dim C As Bit
Declare Sub Wait1()
'~~~~~~~~~~~ Initialization
Cls
Cursor Off
Waitms 500
Home
Lcd "Ready for use...!"
Timer1 = 58335
Start Timer1
'~~~~~~~~~~~ Main program
Do
If C = 1 Then
C = 0
Wait1
End If
Loop
End
'******************
1second:
Stop Timer1
Incr A
Locate 2 , 1
Lcd A
Timer1 = 58335
Start Timer1
If A > 5 Then C = 1
Return
'********************
Sub Wait1()
Incr B
Locate 3 , 1
Lcd "Wait1 occur " ; B ; " times"
Wait 3
End Sub
[/code:1:62feec78da]
↧
BASCOM-AVR : data loss using inkey #2 with software UART : NEWTOPIC
I tried to set up a simple serial communication (9600,8,n,1) between my AtMega88 and a serial device.
First I tested the device using Hyperterm on the PC - everything works fine.
Since the device requests a >CR< after the command (no >LF<) I cannot use >print #1<, but instead >printbin #1<.
I learned that >Print #1< always will send a sequence >CR LF< at the end.
To receive the answer from the device I use >inkey #2< in a loop immediately after.
What happens is that I lose the first up to 10 bytes, but the following bytes are correctly received.
To check whether all bytes are sent correctly from the device I connected the terminal in parallel and indeed they are properly sent.
I am aware that there is no receive buffer for the software UART, but I think it should be possible to correctly receive at 9600 Baud?
Also I saw that the start-up message of the device is always correctly received in case the receiving loop is started before switching ON the device.
Is it possible that there is a delay after sending a command with printbin #1?
[b:4585649bd3][color=red:4585649bd3](BASCOM-AVR version : 2.0.7.6 )[/b:4585649bd3][/color:4585649bd3]
↧
↧
BASCOM-AVR : data loss using inkey #2 with software UART : REPLY
Hi,
try to use the interrupt on pin you use for Software uart, to get attention if byte rx.
I will give you parts of a project of mine, which uses Interrupt Receive on soft serial:
You have to change INT settings! I think you will find out used global variables by yourself, otherwise ask for these...
best, michael
[code:1:15cb25847b]
'-------------------------------------------------------------------------------
' INT0 RX INTERRUPT
'-------------------------------------------------------------------------------
Dim Timeout_rx As Word
Dim Rx_ok As Byte
#if _chip = 168 'Mega168
On Int0 Isr_rx Nosave
Config Int0 = Change
Enable Int0
#endif
#if _chip = 48 ' Mega1280
On Int4 Isr_rx Nosave
Config Int4 = Change
Enable Int4
#endif
Enable Interrupts
' Main here...
do
loop
end
'-------------------------------------------------------------------------------
' RX from WIZ on SoftSerial
'-------------------------------------------------------------------------------
Isr_rx:
#if _chip = 168 ' Mega168
Disable Int0
#endif
#if _chip = 48 ' Mega1280
Disable Int4
#endif
Timeout_rx = 0
Incoming_str = ""
Pos = 1
Do
B = Inkey(#11)
If B > 0 Then
If Pos < 120 Then
Incoming(pos) = B
Incr Pos
End If
Timeout_rx = 0
Else
Incr Timeout_rx
End If
Loop Until Timeout_rx = &H1FFF
'set string end position!
Incoming(pos) = 0
#if Debug_out = 1
Print #1 , Incoming_str
Print #1 , "-"
#endif
Rx_ok = 1
'clear INT0 Int Flag, because int can be flaged in meantime!
#if _chip = 168 ' Mega168
Eifr.intf0 = 1
Enable Int0
#endif
#if _chip = 48 ' Mega1280
Eifr.intf4 = 1
Enable Int4
#endif
Return
[/code:1:15cb25847b]
↧
Share your working BASCOM-AVR code here : Arduino Mega W5100 ethernetshield with SD-card : REPLY
i also found out, that sometimes sd-card works more stable with different settings...
to change SPI settings at runtime for different Hardware i do it this way:
[code:1:4569579720]
'(
*** SPCR SPI CONTROL REGISTER ***
0 = SPR0 SPR1, SPR0: SPI Clock Rate Select 1 and 0
1 = SPR1
SPI2X SPR1 SPR0 SCK Frequency
0 0 0 fosc /4
0 0 1 fosc /16
0 1 0 fosc /64
0 1 1 fosc /128
1 0 0 fosc /2
1 0 1 fosc /8
1 1 0 fosc /32
1 1 1 fosc /64
2 = CPHA CPHA: Clock Phase
3 = CPOL CPOL: Clock Polarity 0 Rising Falling 1 Falling Rising
4 = MSTR MSTR: Master/Slave Select This bit selects Master SPI mode when written to one, and Slave SPI mode when written logic zero.
5 = DORD DORD: Data Order When the DORD bit is written to one, the LSB of the data word is transmitted first.
6 = SPE SPE: SPI Enable
7 = SPIE SPIE: SPI Interrupt Enable
*** SPSR SPI Status Register ***
0 = SPI2X
')
Sub Vs_spi_cs(byval Avtivate As Byte)
' Avtivate MUST BE! 0 or 1
If Avtivate = 0 Then
Set Vs1053_xdcs
Else
#if _xmega = 0
' SPI should be 4-5 MHz!
#if _crystal <= 8000000
Spcr = &B0101_0000
Spsr.spi2x = 1
#else
Spcr = &B0101_0000
Spsr.spi2x = 1
#endif
#endif
Reset Vs1053_xdcs
End If
End sub
[/code:1:4569579720]
↧
BASCOM-AVR : data loss using inkey #2 with software UART : REPLY
Hi Michael,
thanks very much for the reply and the neat solution. :D
My concern ist that in this case my interrupt based the soft clock will not properly work any longer, because the receive loop can take quite some time.
Since my device has a feature to use hardware handshake, I will probably try first to use a port to generate the RTS signal to the device.
What puzzles me is that I have no idea what could cause the delay after the > printbin #1 < command, because the receiving loop follows imediately, there is no code inbetween...
Cheers. Johannes
↧
BASCOM-AVR : data loss using inkey #2 with software UART : REPLY
[quote:9b8abd1e99="jwolf"]I learned that >Print #1< always will send a sequence >CR LF< at the end.[/quote:9b8abd1e99]
Then it might help you to learn, that a semicolon at the end
[code:1:9b8abd1e99]Print Var;[/code:1:9b8abd1e99]
prevents this behaviour.
Also, are you aware, that the output of print and printbin differs ?
[code:1:9b8abd1e99]Dim A As Byte
A = 123
Print A; ' 3 bytes with the ASCII equivalents of 1, 2, 3 are sent
Printbin A ' one byte with value 123 is sent[/code:1:9b8abd1e99]
[quote:9b8abd1e99]What puzzles me is that I have no idea what could cause the delay after the > printbin #1 < command, because the receiving loop follows imediately, there is no code inbetween...[/quote:9b8abd1e99]
Prosaically circumscribing real code isn't helpful at all, so show actual code, if you want a clear response.
↧
↧
BASCOM-AVR : data loss using inkey #2 with software UART : REPLY
Huuu... [quote:882b99f0ce]Prosaically circumscribing [/quote:882b99f0ce] english for runaways :lol: :lol: :lol:
↧
BASCOM-AVR Old versions : timer overflow and wait statement confuse me!? : REPLY
[quote:1107b15fa5]what is happen when hardware stack become overflow? processing stopped or reset occur? [/quote:1107b15fa5]
most likely the system gets crazy. There is no operating system that monitors that and could stop the process or doing a reset - unless you program it by yourself.
↧
BASCOM-AVR : data loss using inkey #2 with software UART : REPLY
[quote:d08abffae0="six1"]english for runaways[/quote:d08abffae0]
I break together :D
↧
BASCOM-AVR : data loss using inkey #2 with software UART : REPLY
I noticed one thing.
Sometimes receiving processing for one sign is much slower than ready function "input". I understand that at the time of receiving the data at the time of execution of the main stops of the body of the program, but no bugs receiving if you want to take a lot of data. Sometimes it can be neglected. For some reason, the port handler software "inkey" - slow.
Ready function INPUT - written in assembler and is faster. :roll:
↧
↧
BASCOM-AVR : data loss using inkey #2 with software UART : REPLY
Thank you MWS for the educative answer:
sorry for the prosa, I am not a software engineer,
but you are fully right that it is obvious to use the expression <print var ;> to avoid sending a <LF>
To show you what I mean with " immediately after" - here are the relevant lines of code:
[code:1:332f62ac0f] Printbin #1 , Tx_buf(1) , X 'output x command bytes
X = 1
Do
B = Inkey(#2)
If B > 0 Then
Rx_buf(x) = B
Incr X
If B = 13 Then 'if CR is send
Incr X
End If
End If
Loop Until B = 62 ' ESC
[/code:1:332f62ac0f]
Thanks for the good hint, Madf, but unfortunately the device I have will reply sending ASCII in multiple lines using <CR> inbetween,
which will stop the input routine after the first line (tried that already :D ).
↧
BASCOM-AVR : data loss using inkey #2 with software UART : REPLY
jwolf, you can change my sample code to read only one byte and return. with pointer to array pos, it might be easy.
also use pushall, popall!
↧
BASCOM-AVR : data loss using inkey #2 with software UART : REPLY
Michael,
[quote:ca3f84a0b6="six1"]with pointer to array pos, it might be easy.[/quote:ca3f84a0b6]
just checked your code a bit closer, tell me: why do you disable/enable external interrupts within the ISR ?
The code runs in the same interrupt routine you explicitly disable, and as long this ISR isn't left, all interrupts including externals interrupts, are disabled anyway.
Only clearing the pending external interrupt flag makes sense.
[quote:ca3f84a0b6]also use pushall, popall![/quote:ca3f84a0b6]
Why ? Simlpy don't use Nosave in the first case.
↧
BASCOM-AVR : data loss using inkey #2 with software UART : REPLY
because of this was a very special case... i only used INT to get first char of stream and ended reading by timeout.
the master plan wasn't to read byte by byte with int!
in fact i don't wanted to disturbed by any other int :lol: that's it oder wie die bayern sagen: host me :lol:
↧
↧
BASCOM-AVR : [ask] read sms in siemens c55 : NEWTOPIC
how command at the command to read sms siemens c55 which the contents of the sms is one letter "y" ?
thank
[b:4e31bb1f9a][color=red:4e31bb1f9a](BASCOM-AVR version : 1.11.9.8 , Latest : 2.0.7.6 )[/b:4e31bb1f9a][/color:4e31bb1f9a]
↧
Share your working BASCOM-AVR code here : RHT03 (DHT22) Sensor : REPLY
I got Peter's code to work without problems with an ATtiny4313. I use it with a Parallax ping transducer to measure the fluid level, temperature and humidity in the head space of a septic holding tank. I will post that code in a few days.
The humidity output I get from the MaxDetect RHT03 sensor compares very well with my home-type humidity sensor.
I had already made a PCB to use analog temperature and humidity sensors when I realized the ATtiny4313 has no ADC. So I went searching for a one-wire device and quickly found the MaxDetect device and also found many folks had problems getting their software to work. So I went to the BASCOM Forum and found Peter's code that he had only downloaded a day or to before. I did the minor conversions for the ATtiny4313 and my port usage and got the code to work very quickly.
So thank you Peter.
↧
Share your working BASCOM-AVR code here : Autopilot using PNI V2Xe Compass Module - Update : REPLY
Peter:
If you go to my profile you will find my email address there. Send me your email address and I will send you the circuit diagram.
Alan
↧