USART help

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
xva3rjy
Posts: 40
Joined: Sat Sep 27, 2014 11:41 am

USART help

Post by xva3rjy » Tue Sep 30, 2014 8:28 pm

Hi I'm very new to coding and am working on a project and hit a wall.

I'm sending data from a PICAXE 20x2 to a 18F2525 then to a GLCD.

As an example the PICAXE is sending the following

Code: Select all

hserout 0,(17,Statusb0,Statusb1)
hserout 0,(23,"PT") 
hserout 0,(24,"T ") 
hserout 0,(25," E") 
hserout 0,(26,"RR") 'Send "PTT  ERR" Message to Display
hserout 0,(17,Statusb0,Statusb1)
hserout 0,(18,FWDPWRb0,FWDPWRb1)
hserout 0,(19,REVPWRb0,REVPWRb1)
hserout 0,(20,TEMPb0,Tempb1)
hserout 0,(21,VOLTAGEb0,VOLTAGEb1)
hserout 0,(22,CURRENTb0,CURRENTb1)
I'm not able to figure out how to store and display the data.
Here is the code on the 18F2525

Code: Select all

Device = 18F2525
Clock =   40                              '  external crystal x 4

#Option GLCD_SCREEN_WIDTH = 192
#Option GLCD_SCREEN_HEIGHT = 64
#Option GLCD_DATA = PORTB
#Option GLCD_RS = PORTA.3
#Option GLCD_CS1 = PORTA.4
#Option GLCD_CS2 = PORTA.5
#Option GLCD_CS3 = PORTC.6
#Option GLCD_RW = PORTA.2
#Option GLCD_EN = PORTA.1
#Option GLCD_RST = PORTA.0
#Option GLCD_MODEL = KS0108

Include "GLCD.bas"
Include "FixedFont.bas"
Include "Arial.bas"
Include "Garamond.bas"
Include "Tahoma.bas"
Include "Verdana.bas"
Include "Times.bas"
Include "DS1307.bas" 
Include "convert.bas"
Include "utils.bas"
Include "graphics.bas"
Include "ks0108.bas"

// import usart module...
Include "usart.bas"

Dim i As Byte

SetBaudrate(br9600)

ADCON1 = $07 // PORTE as digital (GLCD)

SetAllDigital()

GLCD.Cls   
GLCD.SetFont(Fixed)
GLCD.WriteAt(4,2,"RESET")
DelayMS(500)  
GLCD.Cls
                   
While true
 While USART.DataAvailableTimeout(10)
    i = USART.ReadByte()
    USART.WriteByte(i)          //disply to terminal
    GLCD.WriteAt     (2,40,DecToStr(i)+ " hello")  
   Wend
Wend
Any help, pointers etc would be appreciated.

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: USART help

Post by Coccoliso » Fri Oct 03, 2014 2:59 pm

Hello,
I do not know this, nor the PIC PICAXE but to start I think its missing a few lines of CONFIG to be able to run ..
It 's the first time you program a PIC?
I tell you this because at first sight normally serve some instructions that are to be imparted to the device before arriving at the main.
Have you tried to connect a LED with a series resistor (220 ohm) between pin and ground being able to turn it on?
I have learned one thing .. every time you change the device must first try to verify that at least is set correctly, and because each MPU has different parameters .. first you must be able to turn on the LED!

Config example for your device :
- external XTAL with internal PLL
- WatchDog disabled
- RE3 free from MCLR
- PORTB free from A/D
- Single supply disabled

Code: Select all

Config    
  OSC = HSPLL,      'HS oscillator with 4xPLL
  PWRT = ON,        'PWRT enabled
  WDT = OFF,        'WDT disabled
  WDTPS = 32768,    '1:32768
  MCLRE = OFF,      'MCLR pin disabled; RE3 input pin enabled
  LVP = OFF,        'Single-Supply ICSP disabled
  PBADEN = OFF,     'Analog on PORTB<4:0> at reset pins are disabled
  STVREN = OFF,     'Stack full/underflow will not cause Reset
  BOREN = OFF       'Brown-out Reset disabled 
  
'  FCMEN = OFF,      'Fail-Safe Clock Monitor disabled
'  IESO = OFF,       'Oscillator Switchover mode disabled
'  BORV = 3,         'Minimum setting
'  CCP2MX = PORTC,   'CCP2 input/output is multiplexed with RC1
'  LPT1OSC = OFF,    'Timer1 configured for higher power operation
'  XINST = OFF,      'Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
'  DEBUG = OFF,      'Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
'  CP0 = OFF,        'Block 0 (000800-003FFFh) not code-protected
'  CP1 = OFF,        'Block 1 (004000-007FFFh) not code-protected
'  CP2 = OFF,        'Block 2 (008000-00BFFFh) not code-protected
'  CPB = OFF,        'Boot block (000000-0007FFh) not code-protected
'  CPD = OFF,        'Data EEPROM not code-protected
'  WRT0 = OFF,       'Block 0 (000800-003FFFh) not write-protected
'  WRT1 = OFF,       'Block 1 (004000-007FFFh) not write-protected
'  WRT2 = OFF,       'Block 2 (008000-00BFFFh) not write-protected
'  WRTC = OFF,       'Configuration registers (300000-3000FFh) not write-protected
'  WRTB = OFF,       'Boot Block (000000-0007FFh) not write-protected
'  WRTD = OFF,       'Data EEPROM not write-protected
'  EBTR0 = OFF,      'Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
'  EBTR1 = OFF,      'Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
'  EBTR2 = OFF,      'Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
'  EBTRB = OFF       'Boot Block (000000-0007FFh) not protected from table reads executed in other blocks


xva3rjy
Posts: 40
Joined: Sat Sep 27, 2014 11:41 am

Re: USART help

Post by xva3rjy » Sat Oct 04, 2014 5:55 am

My problem is not with the GLCD. It works fine and my code displays the "RESET" word as a test perfectly. What I don't know is how to correctly accept the hserout serial data from the picaxe

Code on PICAXE 20x2
hserout 0,(17,Statusb0,Statusb1)
hserout 0,(23,"PT")
hserout 0,(24,"T ")
hserout 0,(25," E")
hserout 0,(26,"RR") 'Send "PTT ERR" Message to Display

Part of code on 18F2525...
Which of the following do I use?
Dim i As Byte
Dim i As Word
Dim i As string

Do I read it as Byte? or?
i = USART.ReadByte()

Then what?
GLCD.WriteStr
GLCD.WriteAt
GLCD.WriteByte
GLCD.Write

Can I store the info at 23, 24, 25 and recall it to display on GLCD later?

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: USART help

Post by Coccoliso » Sat Oct 04, 2014 8:50 am

Hello,
from what I saw you expect the device attached to the serial port will respond before you do anything,
then maybe it's time to take action on receipt of a byte an example of this is Interrupt_OnData program in Samples\USART folder.

Code: Select all

include "USART.bas"
include "ISRRX.bas"

// RX OnData() event...
sub OnData()
end sub

' program start...
low(PORTD.0)
USART.SetBaudrate(br19200)
ISRRX.Initialize(@OnData)

' loop forever...
while true
   'delayms (500)
   'toggle(PORTD.0)

   ' read data from the buffer and output...
   while ISRRX.DataAvailable
      USART.Write(ISRRX.ReadByte)
   wend 
wend   

in this case as yours since the value returned is a byte variable to use is Byte.
Test in this way even if it seems to me unlikely that the attached device continues to send bytes without solicitation. Usually when I get a particular message send a reply message.
Are you sure the attached device does not need to receive a message before answering?
If you expect that at power up the PIC is able to intercept a single packet of data "one shot" is madness,
should be a kind of handshake between the two .. the pic asks to the device and responds .. and so on.

Another point that I would like to clarify is the RS232 connection you're using a MAX232 or what else ?
This device is RS232 compliant and you must invert the polarity that comes from the UART MCU because is TTL level not inverted.
Attachments
picaxers232.jpg
picaxers232.jpg (73.38 KiB) Viewed 2489 times

Post Reply