Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

soft uart in PIC 16 Basic

Status
Not open for further replies.

hack1nblack

New Member
i wrote some code to send MIDI data over the soft serial port of a PIC 12F1501
at a 4Mhz clock speed it worked,but only upto 28800 baud;not at MIDI's 31.250 baud.
this chip was chosen as the most basic part in the demo version of the new OshonsoftPIC 16 compiler.

my question is ,what is the maximum baud rate acheivable using the soft UART ?
i tried raising the clock rate to 8Mhz but still no joy. at 16Mhz the compiler threw an error and shut down:eek:
 
Sounds to me as if you are struggling with oscillator configuration.... The compiler spitting it's dummy out at 16Mhz makes it seem as if a parameter has a "divide by zero" error and that will cause a run time error..

Can you post your code???
 
Back when... running a pic16F877 at 20Mhz and config the baud with d'09 gives 31.250... Ye its asm, and hw uart but may assist ...
Code:
;
;
; CONFIGURE THE BAUD RATE GENERATOR
;
    BANK1
         MOVLW   D'09'           ; 31,250 MIDI BAUD RATE(20MHZ XTAL)
        MOVWF   SPBRG           ; IN BANK 1
        MOVLW   B'00100000'     ; BRGH = 0 & ASYNC TRANSMISSION
        MOVWF   TXSTA           ; IN BANK 1
        MOVLW    B'00100000'    ; RCIE = RC INTERRUPT ENABLE
        MOVWF    PIE1        ; ENABLE
        BANK0
        MOVLW   B'10010000'     ; ASYNC RECEPTION
        MOVWF   RCSTA           ; IN BANK 0
        MOVF    RCREG,W         ; FLUSH THE RX BUFFER IN BANK 0
        CLRF    PIR1        ; CLEAR FLAGS
 
Last edited:
my MIDI splurger code, a basic try-out to use soft uart on a modern 8-pin uart-less (cheap!)PIC;as the newer parts are plenty fast enough
i'm unsure as to wether i'm just running too fast for the soft uart;i've tried various clock speeds;20Mhz caused a compiler crash.
still waiting for the definitive answer from Vladimir,maybe i'm running in diving boots! i havn't found away of adjusting the baud rate,
as mentioned in the help file;typing in a slighly altered number simply causes an warning message about using a non-standard number...

code (text):

'MIDI out for 12F1501 11/10/2015
'sends voice,controller,value in MIDI format
'from portA.0 (pin7)

Define CLOCK_FREQUENCY = 4
'clock is 4Mhz; done here also
'so we know it's in the listing!
ConfigPin PORTA.0 = Output
Dim voice As Byte
Dim cntrnr As Byte
Dim vals As Byte
voice = 0x90
cntrnr = 0x3c
vals = 0x7f

Define SEROUT_DELAYUS = 1000

Serout PORTA.0, 31250, voice, cntrnr, vals '31250Khz baud rate
'for soft UART;this chip has no hardware one...


'to-do; end the loop after successful transmission.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top