View previous topic :: View next topic |
Author |
Message |
madhav1080
Joined: 06 Jan 2008 Posts: 41 Location: Hyderabad
|
Posted: Sun Jan 06, 2008 8:12 am Post subject: Serial communication problem |
|
|
Hi,
My application requires A host micro (ATMEGA128) to talk to two slave controllers (ATMEGA88) on RS232 serial bus. The host controller sends commands. This in turn turns the on-chip PWM in either of the controllers. The first M88 slave has an ID=1 stored in its eeprom, like wise the second slave M88 has another ID=3 stored in its EEPROM.
The PWM of each chip controls a proportional solenoid (Dweyer). Also each controller is also configured for reading data from a sensor.
The slave with ID =1 reads a POT on Ch0 & TSL250 on Ch1, Similarly the slave with ID = 2 reads another POT on its CH0 and TGS813 on its CH1.
This information is of my intrest. The pot on each chip's Ch0 sets the threshold to fire an alarm if the sensor output exceeds the threshold.
To read the CH data from either of the controller, I am using serial transmission from the slave to the host.
i.e When a switch unique to each slave is pressed it automatically transmits the POT & the respective sensor data.
The funny thing I am facing is that NO data is transmitted from the respective controller when the specific switch is pressed.
The arrangement I have is as follows...
TX of ID = 1 Shorted to TX of ID = 2 and connected to Pin10 of MAX232
RX of ID = 1 shorted to RX of ID = 2 and connected to Pin9 of MAX232
Both controllers are on the same board powered by a common supply, running the same program, also programmed through a common ISP, the only difference is the ID, this is programmed into each device through a utility that I rote using Realbasic.
To test the working I am currently using the PC (with program written in Realbasic) to talk to either of the devices & receive the data from the devices.
Both the devices receive commands from the PC, set the desired PWM thus controlling the respective valve. However when I press a switch on the specific slave, the data should be transmitted from the slave. This is not happening.
When the switch is pressed, that controller transmits the CH0 & CH1 data to the PC, the other controller is not transmitting because, it switch is not pressed. Logically both the TX pins are high.
However when I disconnected the TX-TX short between the controllers both of them are transmitting. Strangely to check I wrote a different program where in both controllers without any key press automatically transmit “Hello”. The data is of course corrupt , but both controllers are transmitting.
Strangely I have used a similar arrangement with tiny2313 again three controllers, two slaves (tiny2313’s) one master M8535, the only difference in this design was that the TTL level was only used (no RS232) like in the M88 design.
Can anybody through some light
|
|
Back to top |
|
|
DJD XTREEM
Joined: 24 Jun 2004 Posts: 190 Location: 127.0.0.1
|
Posted: Sun Jan 06, 2008 10:03 am Post subject: |
|
|
First of all. Without some code it is hard to debug what is going on. Maybe there is a problem in your program for instance..
But as i read this and you say that it works when you disconnect on of the controllers my guess is that because there TX pins are both HIGH. When 1 try's to pull it down for data transmission the other stays high and blocks the way to send it. It's like the other chips is serving a heavy pull-up if the 1 try's to send.
Try to add something like a 10K resistor in each TX line. This could solve the problem. Also check your baudrate!!! Test suchs things on a low baudrate.
Daniel _________________ Bascom AVR 1.11.8.8 full version
STK500 Programmer
ISP Programmer |
|
Back to top |
|
|
madhav1080
Joined: 06 Jan 2008 Posts: 41 Location: Hyderabad
|
Posted: Tue Jan 08, 2008 5:43 pm Post subject: Thanks for the reply |
|
|
Hi,
Well Daniel, thanks for the suggestion, I did try out the 10K pull-up as you suggested, it has no effect.
I am posting the code here...
Code: |
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' PROP GAS BOX AUX BOARD
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$crystal = 10000000
$baud = 9600
Config Adc = Single , Prescaler = Auto
Start Adc
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' PORT Declarations
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Config Portb.1 = Output
Config Portb.2 = Output ' PWM output on OC1B
Config Pind.1 = Output
Config Pind.2 = Input ' SW sens
Config Portd.4 = Input ' Enable Sensing (Flame/GAs)
Config Portd.5 = Output
Config Portd.7 = Output ' Logic output to host (Based on thresh comp)
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' System Variable declaration
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Dim Id As Byte , Rxbyte As Byte
Dim Chno As Byte , Avg10 As Single
Dim Rcdat(10) As Single , Filtvlt As Single , Thresh As Single , Snsout As Single
Dim Pwmcount As Integer
Dim Srlint As Bit , Rxdata As Integer
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' System Subroutine Declaration
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Declare Sub Onbrd_adc(byval Chno As Byte)
Declare Sub Chck_comnd()
Declare Sub Get_adc()
Declare Sub Get_thresh()
Declare Sub Set_thresh()
Declare Sub Get_id()
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' System Interrupt Declarations
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Enable Interrupts
Enable Urxc
Disable Utxc
On Urxc Srlisr
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' System Main Routine
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Tccr1a = &H23
Tccr1b = &H03
Reset Portb.1
Call Get_id
Call Get_thresh
Do
Call Chck_comnd
Call Set_thresh
For Chno = 0 To 1
Call Get_adc
Next
If Pind.4 = 0 Then
If Snsout > Thresh Then
Set Portd.7
Else
Reset Portd.7
End If
Else
Set Portd.7
End If
Print "Hello" ' This get transmitted (both devices transmit), gibbrish!
Loop
End
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Read Chip ID
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub Get_id()
Readeeprom Id , 15
If Id > 10 Then
Do
Call Chck_comnd
Loop Until Rxbyte = 1 Or Rxbyte = 3
Else
If Id = 1 Or Id = 3 Then
Set Portb.1
End If
End If
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Check Serial Command
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub Chck_comnd()
Local Temp As Integer
If Srlint = 1 Then
Select Case Rxbyte
Case Is = 1:
Id = Rxbyte
If Pind.2 = 0 Then
Writeeeprom Id , 15
End If
Case Is = 3:
Id = Rxbyte
If Pind.2 = 0 Then
Writeeeprom Id , 15
End If
Case Is = 10:
Disable Urxc
Inputbin Rxdata
Select Case Rxdata
Case Is = 110:
If Id = 1 Then
Pwmcount = Pwmcount + 1
Ocr1bl = Low(pwmcount)
Ocr1bh = High(pwmcount)
End If
Case Is = 120:
If Id = 1 Then
Pwmcount = Pwmcount - 1
Ocr1bl = Low(pwmcount)
Ocr1bh = High(pwmcount)
End If
Case Is = 130:
If Id = 1 Then
Pwmcount = Pwmcount + 10
Ocr1bl = Low(pwmcount)
Ocr1bh = High(pwmcount)
End If
Case Is = 140:
If Id = 1 Then
Pwmcount = Pwmcount - 10
Ocr1bl = Low(pwmcount)
Ocr1bh = High(pwmcount)
End If
Case Is = 150:
If Id = 1 Then
For Chno = 0 To 1
Call Get_adc
Next
Print Thresh ; "," ; Snsout
End If
End Select
Case Is = 20:
Disable Urxc
Inputbin Rxdata
Select Case Rxdata
Case Is = 310:
If Id = 3 Then
Pwmcount = Pwmcount + 1
Ocr1bl = Low(pwmcount)
Ocr1bh = High(pwmcount)
End If
Case Is = 320:
If Id = 3 Then
Pwmcount = Pwmcount - 1
Ocr1bl = Low(pwmcount)
Ocr1bh = High(pwmcount)
End If
Case Is = 330:
If Id = 3 Then
Pwmcount = Pwmcount + 10
Ocr1bl = Low(pwmcount)
Ocr1bh = High(pwmcount)
End If
Case Is = 340:
If Id = 3 Then
Pwmcount = Pwmcount - 10
Ocr1bl = Low(pwmcount)
Ocr1bh = High(pwmcount)
End If
Case Is = 350:
If Id = 3 Then
For Chno = 0 To 1
Call Get_adc
Next
Print Thresh ; "," ; Snsout
End If
End Select
Case Is = 30:
Disable Urxc
Inputbin Rxdata
Temp = Rxdata
If Id = 1 Then
Pwmcount = Temp - 1000
Ocr1bl = Low(pwmcount)
Ocr1bh = High(pwmcount)
End If
Case Is = 40:
Disable Urxc
Inputbin Rxdata
Temp = Rxdata
If Id = 3 Then
Pwmcount = Temp - 3000
Ocr1bl = Low(pwmcount)
Ocr1bh = High(pwmcount)
End If
Case Is = 253:
Print Thresh ; Chr(13)
Case Is = 254:
Print Snsout ; Chr(13)
End Select
'Wait 1
Srlint = 0
Enable Urxc
End If
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Set Threshold
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub Set_thresh()
If Pind.2 = 0 Then
Enable Utxc
Set Portd.5
Do
For Chno = 0 To 1
Call Get_adc
Next
Print Thresh ; "," ; Snsout
Waitms 100
Loop Until Pind.2 = 1
Disable Utxc
If Thresh < Snsout Then
Reset Portd.5
End If
End If
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Get Background Light
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub Get_thresh()
Local Portdat As Integer
Local Samples As Byte
Local Volt As Single
Local Avgdat As Single
Chno = 1
Avgdat = 0
For Samples = 1 To 10
Portdat = Getadc(chno)
Volt = Portdat * 0.0048828
Avgdat = Avgdat + Volt
Next
Avgdat = Avgdat / 10
Thresh = Avgdat
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Get ADC
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub Get_adc()
Local Lp1vlt As Single
Local Lp2vlt As Single
Local Lp1 As Byte
Local Lp2 As Byte
Lp2vlt = 0
For Lp2vlt = 1 To 10
Lp1vlt = 0
For Lp1 = 1 To 10
Call Onbrd_adc(chno)
Lp1vlt = Lp1vlt + Filtvlt
Next
Lp1vlt = Lp1vlt / 10
Lp2vlt = Lp2vlt + Lp1vlt
Next
Lp2vlt = Lp2vlt / 10
Select Case Chno
Case Is = 0:
Snsout = Lp2vlt
Case Is = 1:
Thresh = Lp2vlt
End Select
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' On board ADC
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub Onbrd_adc(byval Chno As Byte)
Local Portdat As Integer
Local Samples As Byte
Local Volt As Single
Local Filtsmpl As Byte
Local Hthresh As Single
Local Lthresh As Single
Avg10 = 0
Filtsmpl = 0
For Samples = 1 To 10
Portdat = Getadc(chno)
Volt = Portdat * 0.0048828
Avg10 = Avg10 + Volt
Rcdat(samples) = Volt
Next
Avg10 = Avg10 / 10
Hthresh = Avg10 + 0.0025
Lthresh = Avg10 - 0.0025
Filtvlt = 0
For Samples = 1 To 10
If Rcdat(samples) > Lthresh And Rcdat(samples) < Hthresh Then
Filtvlt = Filtvlt + Rcdat(samples)
Incr Filtsmpl
End If
Next
If Filtsmpl > 0 Then
Filtvlt = Filtvlt / Filtsmpl
Else
Filtvlt = Avg10
End If
End Sub
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' System Interrupt routines
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Serial Interrupt
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Srlisr:
Srlint = 1
Rxbyte = Udr
Return
|
|
|
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
|
|