<How to> Serial communication with 12f683 and "Serial Init"

Ir abajo

<How to> Serial communication with 12f683 and "Serial Init"

Mensaje por cosmok82 el Mar 3 Jul 2012 - 17:28

Hi,
I'm new to the forum, but I hope you can answer my question.
I made this simple source code from the example shown here under "SerSend".

Código:
;Chip Settings
#chip 12F683,8
#config OSC=INT

;Defines (Constants)
#define SendAHigh Set PORTA.1 ON
#define SendALow Set PORTA.1 OFF

TRISA = 0b0100
Dir PORTA.1 Out

'GPO,0 (RX) <- TX
'GPO,1 (TX) -> RX
InitSer(1, r2400, 1+WaitForStart, 8, 1, None, Normal)
Do Forever
    'send A letter
    SerSend 1, 65
    Wait 100 ms
Loop
But it don't work.

Could you explain why? Thanks for the support leaving.

cosmok82
Nuevo Usuario
Nuevo Usuario

Mensajes : 3
Fecha de inscripción : 03/07/2012

Volver arriba Ir abajo

Re: <How to> Serial communication with 12f683 and "Serial Init"

Mensaje por Pikitin el Jue 5 Jul 2012 - 9:05

Hi cosmok82.

I ussually see using GPIO on 12f683, not PORTA, may be this help.

Anyway.. what do you mean with it doesn't work?
Don't receive anything?.. receive garbage?

I guess you are receiving data in some serial terminal at PC.. is the port, baudrate, etc. correctly configured?

Is the Pic working at all?? for example try this with a led or voltmeter at GPIO.0:
Código:
Do Forever
    'send A letter
    SerSend 1, 65

    set GPIO.0 on
    Wait 500 ms
    set GPIO.0 off
    Wait 500 ms
Loop

You can also ask in GcBasic forums:
http://sourceforge.net/projects/gcbasic/forums

Regards.

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

Re: <How to> Serial communication with 12f683 and "Serial Init"

Mensaje por cosmok82 el Jue 5 Jul 2012 - 13:39

Pikitin escribió:Hi cosmok82.

I ussually see using GPIO on 12f683, not PORTA, may be this help.

Anyway.. what do you mean with it doesn't work?
Don't receive anything?.. receive garbage?

I guess you are receiving data in some serial terminal at PC.. is the port, baudrate, etc. correctly configured?

Is the Pic working at all?? for example try this with a led or voltmeter at GPIO.0:
Código:
Do Forever
    'send A letter
    SerSend 1, 65

    set GPIO.0 on
    Wait 500 ms
    set GPIO.0 off
    Wait 500 ms
Loop

You can also ask in GcBasic forums:
http://sourceforge.net/projects/gcbasic/forums

Regards.

Código:
;Chip Settings
#chip 12F683,8
#config OSC=INT

;Defines (Constants)
#define SendAHigh Set GPIO.0 ON
#define SendALow Set GPIO.0 OFF

Dir GPIO.0 Out
'GPIO,0 (TX) -> RX
'GPIO,1 (RX) <- TX
InitSer(1, r2400, 1+WaitForStart, 8, 1, None, Normal)
Do Forever
    'send A letter
    SerSend 1, 65

    set GPIO.0 on
    Wait 100 ms
    set GPIO.0 off
    Wait 100 ms
Loop

I tried this code, which should now be corrected, but I get nothing; except a character similar at "+" (I don't can write it because it isn't a printable).

Perhaps it simply lacks support for a software UART.

cosmok82
Nuevo Usuario
Nuevo Usuario

Mensajes : 3
Fecha de inscripción : 03/07/2012

Volver arriba Ir abajo

Re: <How to> Serial communication with 12f683 and "Serial Init"

Mensaje por Pikitin el Vie 6 Jul 2012 - 7:31


I tried this code, which should now be corrected, but I get nothing;
except a character similar at "+" (I don't can write it because it
isn't a printable).

Perhaps it simply lacks support for a software UART.

InitSer and SerSend belongs to the software uart of GcBasic: http://gcbasic.sourceforge.net/newfiles/help/
And your first code looks to be correct, that's why i sugested that something could be wrong with hardware or pic configuration (perhaps clock config).
That is the reason of:
Código:

    set GPIO.0 on
    Wait 500 ms
    set GPIO.0 off
    Wait 500 ms
This way you can test that pic works and do it at correct speed: if you hook a led to GPIO.0.. it blinks at aproxs 1 Hz??

But for doing this you should use other pin than used in serial, for example:
Código:
;Chip Settings
#chip 12F683,8
#config OSC=INT

;Defines (Constants)
#define SendAHigh Set GPIO.1 ON
#define SendALow Set GPIO.1 OFF

Dir GPIO.0 Out
'GPIO,1 (TX) -> RX

InitSer(1, r2400, 1+WaitForStart, 8, 1, None, Normal)
Do Forever
    'send A letter
    SerSend 1, 65

    set GPIO.0 on
    Wait 500 ms
    set GPIO.0 off
    Wait 500 ms
Loop

Note that SendSerial use GPIO.1, and "test pin" is GPIO.0.

"receive pin" is not defined (guess it doesn't matter while you don't use SerReceive).

Another thing you ca try, if you are using internal oscillator:
#config OSC=INTRC_OSC_NOCLKOUT

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

SOLVED

Mensaje por cosmok82 el Mar 10 Jul 2012 - 17:37

I solved it and carry the code below;

Código:
;Chip Settings
#chip 12F683,8
#config MCLRE=OFF, WDT=OFF

;Defines (Constants)
#define SendAHigh Set GPIO.0 Off
#define SendALow Set GPIO.0 On
#define RecAHigh GPIO.1 = Off
#define RecALow GPIO.1 = On

'8MHz internal clock
OSCCON = b'01110001'

InitSer 1, r4800, 1+WaitForStart, 8, 1, None, Invert

'GPIO,0 as TX
Dir GPIO.0 Out

Main:
    SerSend 1, b'01000001'
    SerSend 1, "!"
    SerSend 1, " "
    SerSend 1, "a"
    SerSend 1, "l"
    SerSend 1, " "
    SerSend 1, "l"
    SerSend 1, "u"
    SerSend 1, "p"
    SerSend 1, "o"
    SerSend 1, " "
    FOR i = 0 to 4
        SerSend 1, "."
    NEXT
    SerSend 1, 13
    Wait 100 ms
    SerSend 1, 10
    Wait 100 ms
goto Main

In my interface I always worked with GPIO.0 as output and GPIO.1 as input (although this one into the code hasn't been set yet). From the tests I conducted it appears that 4800 baud rate is the maximum attainable output with 8MHz internal oscillator.
The code outputs the text:

Código:
A! al lupo .....

and you can see from the code the different input formats that make the text.

I thank everyone who helped me and I want to say that it will soon publish my project development, on my site www.creativityslashdesign.tk , complete with tutorial with the use of GCB (it is only a preview for now).

I hope you follow me.

cosmok82
Nuevo Usuario
Nuevo Usuario

Mensajes : 3
Fecha de inscripción : 03/07/2012

Volver arriba Ir abajo

Re: <How to> Serial communication with 12f683 and "Serial Init"

Mensaje por Contenido patrocinado


Contenido patrocinado


Volver arriba Ir abajo

Volver arriba

- Temas similares

 
Permisos de este foro:
No puedes responder a temas en este foro.