usart-bluetooth problem



THE BOOK of DT's INTERRUPTS is an organization of interrupt service routines and other works written by Darrel Taylor, RIP.

Interrupt routines are arranged per Darrel's original list. Darrel Taylor's Instant Interrupts are an extension of the work of Tim Box whom in October of 2002 wrote INT_CTRL.pbp

Many of the forum members felt this is a long overdue project.

THE BOOK of DT's INTERRUPTS
will be a valuable resource and a tribute to Darrel Taylor the "Fanatical Contributor".

THE BOOK of DT's INTERRUPTS is located at http://dt.picbasic.co.uk/

+ Reply to Thread
Results 1 to 33 of 33
  1. #1
    Join Date
    Dec 2014
    Posts
    14

    Post usart-bluetooth problem

    hi,
    1. i want to send a packet of data from pc to pic via bluetooth hc 06 module. the dimension of the package is 512 byte string. i use windows 8 so i dont have hyperterminal, i use putty instead. i decided to send only one byte from pc at first but couldnt succeed. and how can i do it using hserin commands?
    2. i use putty for the first time. after pairing with the device, the black screen show up but i can not type anyting, can not see what i type
    thanks


    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 21.10.2013 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    DEFINE OSC 4
    'device 18f452
    asm
    __CONFIG _CONFIG1H, _OSCS_OFF_1H & _LVP_OFF_4L & _DEBUG_OFF_4L & _PWRT_ON_2L & _XT_OSC_1H & _BOR_OFF_2L & _WDT_OFF_2H
    endasm




    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 5
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_RSBIT 6
    DEFINE LCD_RWREG PORTD
    DEFINE LCD_RWBIT 4
    DEFINE LCD_BITS 4
    DEFINE LCD_Lines 2


    ADCON0=%01000101
    ADCON1=%10001110
    DEFINE ADC_BITS 10 'Number of bits in ADCIN result
    DEFINE ADC_CLOCK 3 'ADC clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50


    DEFINE HSER_BAUD 9600
    DEFINE HSER_SPBRG 25
    DEFINE HSER_RCSTA 90h'%10010000
    DEFINE HSER_TXSTA 24h'%00100100
    DEFINE HSER_CLROERR 1


    A VAR WORD
    DATAIN VAR BYTE
    DATAFLAG VAR BIT
    symbol LED=PORTE.1
    RCIF VAR PIR1.5




    TRISA.0=1
    TRISC.7=1
    TRISC.6=0
    TRISE.1=0


    INTCON = %11000000 ' enable global and peripheral and portb change interrupts
    PIE1.5=1 'enable rx interrupt
    PIR1.5=0


    LCDOUT $FE,1
    LED=1:
    PAUSE 2000:
    LED=0
    PAUSE 1000


    DATAFLAG=0
    DATAIN=0


    LCDOUT $FE,1,"OPENiNG"
    LCDOUT $FE,$C0,"DATA: ", DEC DATAIN
    pause 1000


    On Interrupt GoTo HANDLER




    MAIN:
    IF DATAFLAG=1 THEN
    DATAFLAG=0
    HSEROUT [13,10,dec DATAIN]
    LCDOUT $FE,1,"DATA: ",DEC DATAIN
    FOR A=0 TO 65000
    PAUSEUS 10
    NEXT A
    ENDIF
    IF DATAFLAG=0 THEN
    LCDOUT $FE,1,"NOT ARRiVED"
    FOR A=0 TO 65000
    PAUSEUS 10
    NEXT A
    ENDIF
    GoTo MAIN


    Disable
    HANDLER:
    DATAIN=RCREG
    DATAFLAG=1
    PIR1.5=0
    Resume
    Enable
    End

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,421


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    Hi,
    1) Start by getting your serial comms working without interrupt. Then add the interrupt capabillity later.
    Code:
    INIT:
       HSEROUT["Program Start",10,13]
    
    Main:
       HSERIN[Char] 
       LCDOUT $FE,1,"DATA: ", Char
       HSEROUT[Char]
       TOGGLE LED
    GOTO Main
    2) My guess would be that PUTTY is set so that it displays what the device echos back and not what you type locally and since your device isn't currently echoing what you type you don't get anything in window (many serial terminals work this way by the way). Check the documentation for PUTTY.

    Finally, please use the code tags when posting code - here's how to do it.

    /Henrik.

  3. #3
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    thank you for your answer hendrik. do i need to put "pause" in main routine in order to see blinking of led?

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,421


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    Hi,
    No. HSERIN will sit there waiting untill it does get a byte so the LED will toggle one time for each byte it receives. If nothing comes in the LED won't toggle.

    /Henrik.

  5. #5
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    henrik, i did what you said but nothing has changed- neither led nor data. what do you think? can it be about hardware?

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,421


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    Then I'm afraid it's back to basics....and of course it can be a hardware issue.

    Is the PIC actually running and if so is it running at the correct speed?

    Do a blink-a-led program and verify that first.
    Then start focusing on the serial comms but do it with a wired connection first. Once you have THAT going, switch to your Bluetooth module. Right now there are SO many things that can be wrong.....

    * PIC is not running at the correct speed.
    * Hardware problem between PIC and Bluetooth module.
    * Wrong baudrate between PIC and Bluetooth.
    * Wrong baudrate on the virtual COM port,
    * Wrong settings in PUTTY.


    You get the idea.....

  7. #7
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    first of all, happy new year
    i went to basics and checked all the peripherals-led blinkings-analog converter- lcd drive... there is no problem. at the end, i succeed to pair with pc via bluetooth. the led on hc 06 is not blinking after pairing. everything looks allright. connection settings are the same on the two side- putty and computer's comport settings.
    but i can not get it back what i send from putty- no echo
    so there can be 2 reason to be a failure left:
    1. because of wiring between pic and bluetooth module... (in fact, i dont think so)
    2. codes...

    henrik, can you check out my codes?
    thanks a lot...
    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 21.10.2013                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    DEFINE OSC 4
    
    'asm
    ' __CONFIG _CONFIG1H, _OSCS_OFF_1H & _LVP_OFF_4L & _DEBUG_OFF_4L & _PWRT_ON_2L & _XT_OSC_1H & _BOR_OFF_2L & _WDT_OFF_2H
    'endasm
    
    
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 5
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_RSBIT 6
    DEFINE LCD_RWREG PORTD
    DEFINE LCD_RWBIT 4
    DEFINE LCD_BITS 4
    DEFINE LCD_Lines 2
    
    'ADCON0=%01000101     
    'ADCON1=%10001110  
    'DEFINE ADC_BITS 10 'Number of bits in ADCIN result
    'DEFINE ADC_CLOCK 3 'ADC clock source (rc = 3)
    'DEFINE ADC_SAMPLEUS 50 
    
    DEFINE HSER_BAUD 9600 
    DEFINE HSER_SPBRG 25 
    DEFINE HSER_RCSTA 90h'%10010000  
    DEFINE HSER_TXSTA 24h'%00100100
    DEFINE HSER_CLROERR 1
    
    A VAR WORD
    'DATAIN VAR BYTE
    'DATAFLAG VAR BIT
    symbol LED=PORTE.1
    'RCIF VAR PIR1.5 
    CHAR var byte
    RCIF VAR PIR1.5  
    
    TRISA.0=1
    TRISC.7=1
    TRISC.6=0
    TRISE.1=0  
    
    'INTCON = %11000000 ' enable global and peripheral and portb change interrupts
    'PIE1.5=1 'enable rx interrupt
    'PIR1.5=0 
    
    LCDOUT $FE,1
    LED=1:
    PAUSE 2000:
    LED=0
    PAUSE 1000
    
    'DATAFLAG=0
    'DATAIN=0
    
    LCDOUT $FE,1,"OPENING"
    'LCDOUT $FE,$C0,"DATA: ", DEC DATAIN
    pause 1000
    
    'On Interrupt GoTo HANDLER
    INIT:
       HSEROUT["Program Start",10,13]
    
    Main:
    WHILE RCIF  
              CHAR=RCREG
              HSEROUT[Char,10,13]
              LCDOUT $FE,1,"DATA: ", dec Char
              TOGGLE LED
    WEND   
    GOTO Main
        
    
    'Disable 
    'HANDLER:
    'DATAIN=RCREG
    'DATAFLAG=1
    'PIR1.5=0
    'Resume
    'Enable     
    End

  8. #8
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    If you post the wiring of your setup, you Could get a better help. Are aware that the hc06 module works @ 3.3 volts ? At which voltage your pic Is operating ?

    Happy new Year to all

    Al.
    All progress began with an idea

  9. #9
    Join Date
    Dec 2010
    Posts
    401


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    Unless you have successfully used Putty for this application before, I think it might not be the best choice. It has default configuration and protocols that will give you trouble. Instead search for and download the free "Bray's terminal.exe". I've used version 1.9b for this and many other similar applications, after giving up on Putty. It's a much better replacement for Hyperterminal - even if you still have an OS with Hyperterminal.

  10. #10


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    to check communication link....... program a a pic or your pic to serout.... some data..... 1,2,3,4 a,b,c,d every second or so.
    the bt module to pic baud rate must match... but the blue tooth to pc link makes its own rate. on pc windows 8 make sure to use/try com port taken by Bluetooth device. It uses SPP..... serial port profile which sets up the com port (you can see on bt-settings). then you can make sure the T and R 's are hooked properly for pic. that way you can start checking basic communication on bt.
    don

  11. #11


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    to test bt link, program a pic to serout some data say "1,2,3,4 a,b,c,d" every second or so to the bt module. the baud from pic to module should match but the bt to pc link makes its own rate. I'm sure you found the com port created by the bt device through the SPP - serial port profile mode seen in bt settings on win8. on my device bt set up 2 com ports of which one works the link. with that you can try/check for the correct T and R connections at pic end.
    I put hyperterm on my win8 just copy pasted 2 files


    Name:  Capture.JPG
Views: 507
Size:  54.8 KBName:  Capture.JPG
Views: 544
Size:  220.6 KB

  12. #12
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    hi;
    i solved my problem when i checked wiring between pic and bluetooth module. then i succeed to send some data from pic to pc. everything works fine; but when it comes to send sth from pc to module, i fail i think there can be two reason for this.
    one: low voltage level for pic-18f452 (data line-3,3 v)
    two: codes...
    what do you think?

    thanks...
    Code:
    DEFINE OSC 4
    
    
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 5
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_RSBIT 6
    DEFINE LCD_RWREG PORTD
    DEFINE LCD_RWBIT 4
    DEFINE LCD_BITS 4
    DEFINE LCD_Lines 2
    
    
    DEFINE HSER_RCSTA 90h'%10010000  
    DEFINE HSER_TXSTA 24h'%00100100
    DEFINE HSER_CLROERR 1
    DEFINE HSER_BAUD 9600 
    DEFINE HSER_SPBRG 25 
    
    A VAR WORD
    symbol LED=PORTE.1
    
    TRISA.0=1
    TRISC.7=1
    TRISC.6=0
    TRISE.1=0  
    
    LCDOUT $FE,1
    LED=1:
    PAUSE 2000:
    LED=0
    PAUSE 1000
    A=0
    LCDOUT $FE,1,"HELLO"
    pause 2000
    
    MAIN:          
    HSERIN [A]
    LCDOUT $FE,1, "A: ", DEC A
    PAUSE 1000
    GOTO MAIN
    
     
    End

  13. #13
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    I would suggest the following items.
    1. Change your "A" variable to a byte instead of a word since asynchronous serial ports transmit and receive ASCII characters which are bytes not words.
    A var byte

    2. Check the manual on HSERIN and use the timeout and label options with your command to help debug the issue.
    Maybe something like this....

    MAIN:

    HSERIN 100, timesup, [A]
    LCDOUT $FE, 1
    LCDOUT $80, "A: ", Dec A
    PAUSE 1000
    GOTO MAIN

    timesup:

    LCDOUT $FE, 1
    LCDOUT $FE, $80, "Timed Out!"
    PAUSE 2000
    GOTO MAIN

    END


    Regards,

  14. #14
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    no change
    Last edited by murat44; - 8th January 2015 at 20:33.

  15. #15
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    Quote Originally Posted by murat44 View Post
    no change
    What do you mean by no change?
    Did the HSERIN timeout and display "Timed Out!" On the LCD?

    Also, as previously suggested, why don't you post a drawing of your circuit and connections. That will help others to understand what you have and potentially be able to offer advice.

    Regards

  16. #16
    Join Date
    Dec 2010
    Posts
    401


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    I repeat...
    Quote Originally Posted by Charlie View Post
    Unless you have successfully used Putty for this application before, I think it might not be the best choice. It has default configuration and protocols that will give you trouble. Instead search for and download the free "Bray's terminal.exe". I've used version 1.9b for this and many other similar applications, after giving up on Putty. It's a much better replacement for Hyperterminal - even if you still have an OS with Hyperterminal.

  17. #17
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    i updated my codes as shown below. lcd always displays "timed out!" even if i send data from terminal. i dont know the reason of this but device is deaf...
    how can it be that the device (pic, i mean) can send data to pc through bluetooth but can not receive data from pc? is it possible? it pairs, sends but can not receive... it looks weird. what can be possible errors about this issue? here is my latest codes and drawings:
    PS: i downloaded Bray's terminal.exe and im using it... as charlie said before, "bray's" is much more better than pussy, sorry putty
    Code:
    DEFINE OSC 4
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 5
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_RSBIT 6
    DEFINE LCD_RWREG PORTD
    DEFINE LCD_RWBIT 4
    DEFINE LCD_BITS 4
    DEFINE LCD_Lines 2
    
    DEFINE HSER_RCSTA 90h'%10010000  
    DEFINE HSER_TXSTA 24h'%00100100
    DEFINE HSER_CLROERR 1
    DEFINE HSER_BAUD 9600 
    DEFINE HSER_SPBRG 25 
    
    A VAR byte
    symbol LED=PORTE.1
    
    TRISA.0=1
    TRISC.7=1
    TRISC.6=0
    TRISE.1=0  
    
    LCDOUT $FE,1
    LED=1:
    PAUSE 2000:
    LED=0
    PAUSE 1000
    A=0
    LCDOUT $FE,1,"HELLO"
    pause 2000
    
    MAIN: 
    LCDOUT $FE, 1
    HSERIN 100, timesup, [A] 
    LCDOUT $FE, 1
    LCDOUT $80, "A: ", Dec A
    PAUSE 1000
    GOTO MAIN
    
    timesup:
    
    LCDOUT $FE, 1
    LCDOUT $FE, $80, "Timed Out!"
    PAUSE 2000
    GOTO MAIN      
    End
    Name:  IMG_435.jpg
Views: 482
Size:  83.4 KB

  18. #18
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    Reading the 18F452 Datasheet, RC6 (USART TX) and RC7 (USART RX) are Schmitt Trigger buffered inputs. Also reading the Datasheet (pg. 265 DC Characteristics) shows the following for ST type I/O pins:
    Input Logic Low: Min = VSS, Max = .2 VDD
    Input Logic High: Min = .8 VDD, Max = VDD

    If you are running your PIC at 5 Vdc then that would translate to:
    Input Logic Low: Min = 0V, Max = 1V
    Input Logic High: Min = 4V, Max 5V

    The HC06 running at 3.3V will not output voltage levels that high so the PIC will not recognize a High Logic Level.

    You'll need to run the PIC at 3.3V, if you can, or you'll have to level shift the I/O between the two devices.
    Regards,
    TABSoft

  19. #19
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    yes, you are right- as always... i noticed schmitt trigger issue after i looked up at the right place in datasheet. can i use a 10 k resistor between 5v and usart rx pin as a level shifter? is it dangerous for modules health?
    thanks...

  20. #20
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    thank you all. everything works fine now

  21. #21
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    i have a string in my pc/terminal and i want to send it to pic. string is sth like: 1F133580235647A848DCD824696A6321551CA53D541E2FF2E2 FC...
    it is 128 hex number in total... i want to get this string as:

    datain[0]: 1F
    datain[1]: 13
    datain[2]: 35
    datain[3]: 80
    datain[4]: 23 ...

    but there is nothing like:

    "HSERIN [STR HEX DATAIN\128]" in PBP...
    what can i do?
    thanks...

  22. #22
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,421


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    Provided all values are represented as two hexadecimal characters:
    Code:
      
    For i = 0 to 127
       HSERIN[HEX2 DataIn[i]]
    NEXT
    /Henrik.

  23. #23
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    i did it as you told but numbers and row are mixed in some cases. this method is not as useful as "hserin [wait ("sync"), str h\128]" one...
    using "for - next" makes "hserin" crippled
    any offer?

  24. #24
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,421


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    > i did it as you told but numbers and row are mixed in some cases
    For the method to work every value MUST be two hexadecimal characters, ie values less than 16 must have leading zeros.

    > this method is not as useful as "hserin [wait ("sync"), str h\128]" one...
    Well, since more usefull method you asked for in the first place doesn't exist and the one you posted above doesn't do what you asked about I'd say "this" method is more useful. Apparently it's not useful enough but without more details about your setup it's hard to guess why.

    > using "for - next" makes "hserin" crippled
    No it doesn't.

    > any offer?
    No, not really unless you provide more details.

    /Henrik.

  25. #25
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    Name:  fff.png
Views: 412
Size:  100.0 KB

    Code:
    DEFINE OSC 4
    
    
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 5
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_RSBIT 6
    DEFINE LCD_RWREG PORTD
    DEFINE LCD_RWBIT 4
    DEFINE LCD_BITS 4
    DEFINE LCD_Lines 2
    
    
    DEFINE HSER_RCSTA 90h'%10010000  
    DEFINE HSER_TXSTA 24h'%00100100
    DEFINE HSER_CLROERR 1
    DEFINE HSER_BAUD 9600 
    DEFINE HSER_SPBRG 25 
    
    A VAR WORD  
    B var word 'ADRES DEĞİŞKENİ 
    C VAR BYTE
    D var byte
    G VAR BYTE[128]
    H VAR BYTE[128]   
    BAYRAK VAR BIT
    
    
    
    SYMBOL LED=PORTE.1
    SYMBOL SCL=PORTC.3
    SYMBOL SDA=PORTC.4
    
    DATAYAZMA CON $A0
    DATAOKUMA CON $A1
    ZAMANYAZMA  CON $D0
    ZAMANOKUMA  CON $D1
    BEKLE CON 25
    
    TRISA.0=1
    TRISC.7=1
    TRISC.6=0
    TRISE.1=0 
     
    
    INTCON = %11000000 ' enable global and peripheral and portb change interrupts
    PIE1.5=1 'enable rx interrupt
    PIR1.5=0 
    
    
    LCDOUT $FE,1,"merhaba"
    pause 2000
    B=0
    PAUSE 500
    
    On Interrupt GoTo KESME
    BASLA:          
             If BAYRAK=0 Then
                LCDOUT $FE,1,"BiLGi BEKLENiYOR"
                For a=0 To 10000
                pauseUS 1
                Next a
                goto BASLA
            EndIf
             IF BAYRAK=1 THEN
                BAYRAK=0  
            ENDIF   
    GOTO BASLA
    
    
    Disable
    KESME:
    
    for d=0 to 63
    hserin [wait ("a"),hex2 H[d]]
    next d
    
    I2CWRITE SDA,SCL,DATAYAZMA,B,[STR H\64]
    PAUSE BEKLE
    I2CREAD SDA,SCL,DATAOKUMA,B,[STR G\64]
    
    HSEROUT [STR G\64]     
    BAYRAK=1     
    ATLA:
    PIR1.5=0
    Resume
    Enable
    End

    i send 64 bytes from pc in total and it sends me back 64 bytes- no problem at this point... but the row, array is mixed
    thanks...
    Last edited by murat44; - 3rd February 2015 at 12:32.

  26. #26
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    This looks like you are trying to write your 64 byte array that you receive from the PC to a I2C EEPROM.
    It looks like the EEPROM may only support a 16 Byte Page Write/Read.
    Check the data sheet for the EEPROM for the Page Write/Read specs.
    Regards,
    TABSoft

  27. #27
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,421


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    Yeah take the EEPROM out of the picture to begin with.
    And I'm not sure about the way you're sending the values back to the PC. From the PC you're sending as ASCII and in interpreting it as 2 digit hex values (each preceeded by an 'a'). You're storing the values as bytes. Then you're sendng them back as a raw (binary) to the PC. Is the terminal program then setup to interprest the value 20 as 14(hex) or how is it supposed to work?

    Code:
    FOR d=0 to 63
       HSERIN [wait ("a"), hex2 H[d]]
    NEXT
    
    FOR d = 0 to 63
       HSEROUT[H[d]]    ' Send raw byte values
    NEXT
    
    ' OR...
    
    FOR d = 0 to 63
      HSEROUT[HEX2 H[d]]    ' Send ASCII text representing the values as two hexadecimal digits
    NEXT
    
    ' OR...
    
    HSEROUT[STR H\64]     ' Send string as raw values

  28. #28
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,421


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    I just verified the method here and it works just fine, with 128 values.
    Here's the code I used:
    Code:
    i       VAR BYTE
    j       VAR BYTE
    Array   VAR BYTE[128]
    
    PAUSE 3000
    
    Main:
      GOSUB ClearArray
    
      HSEROUT["Enter new values...", 13]
      
      For i = 0 to 127
          HSERIN[WAIT ("a"), HEX2 Array[i]]
      NEXT
      
      ' Send values back, the Array[i-1] and i//16 stuff is just there
      ' to format the output a little better, for readabillity.
      For i = 1 to 128
        HSEROUT[HEX2 Array[i-1]]
        IF i // 16 = 0 THEN
            HSEROUT[13]
        ELSE
            HSEROUT[","]
        ENDIF
      NEXT
        
        HSEROUT[13, "DONE", 13]
      
      Goto Main
    
    
    ClearArray:
        For i = 0 to 127
            Array[i] = 0
        NEXT
    RETURN
    And here's the result:

    Name:  HEX string.jpg
Views: 407
Size:  89.0 KB

    Now, this was on a 18F25K20 running at 64MHz, which is 16 times faster than 4MHz. On the other hand I used 115200 baud which is 12 times faster than 9600. If it refuses to work at your end then, as a test, decrease the baudrate or increase the oscillator speed.

    /Henrik.

  29. #29
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    I agree Henrik.

    Works fine in the simulator, given you set the output method the way you need.

    I also ran Murat's software through the simulator with a simulated 24C256 EEPROM.
    This works fine as well since the 24C256 supports a 128 byte page write operation.

    I bet the issue Murat is that the EEPROM you are using does not support a 64 byte page write.
    What EEPROM are you using?

    Also, with PBP (not PB) you do not need to change the Control byte of the I2C Read/Write commands.
    You are setting the I2CWRITE control byte to ($A0) and then the I2CREAD control byte to ($A1).
    PBP takes care of setting the LSB of the control byte for you.
    For either a Write or Read, the control byte should be $A0.
    This is indicated in the manual for the I2CREAD command.

    So your I2C operations should look like this.

    I2CWRITE SDA,SCL,DATAYAZMA,B,[STR H\64]
    PAUSE BEKLE
    I2CREAD SDA,SCL,DATAYAZMA,B,[STR G\64]

    Where DATAYAZMA = $A0.
    Regards,
    TABSoft

  30. #30
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    strange, weird things happen in my terminal program. i use Bray's terminal as a communicator but the results are so silly as in my last post. i tried pic basic pro's serial communicator like Henrik and the results are totally different. everything looks tidy and the results are the same as what they should be... BUT sometimes-rarely- last byte of array stays in rcreg and it became the first byte of next packet how can i overcome this problem?
    for example:

    Name:  iiii.png
Views: 390
Size:  358.5 KB

    eeprom:24c512

  31. #31
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,421


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    You're going to have to post your code so we can see what you're doing.

  32. #32
    Join Date
    Dec 2014
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    Code:
    DEFINE OSC 4
    
    
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 5
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_RSBIT 6
    DEFINE LCD_RWREG PORTD
    DEFINE LCD_RWBIT 4
    DEFINE LCD_BITS 4
    DEFINE LCD_Lines 2
    
    
    DEFINE HSER_RCSTA 90h'%10010000  
    DEFINE HSER_TXSTA 24h'%00100100
    DEFINE HSER_CLROERR 1
    DEFINE HSER_BAUD 9600 
    DEFINE HSER_SPBRG 25 
    B var word
    i var byte
    H VAR BYTE[128]
    G VAR BYTE[128]
    TEMP VAR BYTE
    
    symbol LED=PORTE.1
    SYMBOL SCL=PORTC.3
    SYMBOL SDA=PORTC.4
    
    DATAYAZMA CON $A0
    DATAOKUMA CON $A1
    ZAMANYAZMA  CON $D0
    ZAMANOKUMA  CON $D1
    BEKLE CON 25
    
    TRISA.0=1
    TRISC.7=1
    TRISC.6=0
    TRISE.1=0 
     
    
    INTCON = %11000000 ' enable global and peripheral and portb change interrupts
    PIE1.5=1 'enable rx interrupt
    PIR1.5=0 
    
    LCDOUT $FE,1,"merhaba"
    pause 2000
    
    On Interrupt GoTo KESME
    B=0
    
    BASLA:  
    LCDOUT $FE,1     
    For i=0 to 127
    H[i]=0
    G[i]=0
    NEXT
    GOTO BASLA
    
    Disable
    KESME:
    
    For i = 0 to 127
    HSERIN [HEX2 H[i]]
    nEXT i
    
    i2cwrite sda,SCL,datayazma,B,[str H\128]
    pause bekle
    i2cread sda,SCL,DATAYAZMA,B,[STR G\128] 
    For i = 0 to 127
    HSEROUT[HEX2 G[i]]
    IF i // 20 = 0 THEN
    HSEROUT[13]
    ELSE
    HSEROUT[","]
    ENDIF
    NEXT
    HSEROUT[13, "-bitti-", 13]     
    PIR1.5=0
    Resume
    Enable
    End
    after resetting pic, problem solves but i can't do it while it is running. as far as i think, it is an overflow error. because when i send another packet before it is "sending the data package back to pc" operation complete, problem occurs... using buffer or overflow error cause this problem...

  33. #33
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: usart-bluetooth problem

    Murat.

    Perhaps you are experiencing a USART overrun condition in your ISR when you are reading the packet from the PC using "HSERIN".

    I would try a couple of things to narrow this issue down.
    1. Comment out the following line at the beginning of your code "DEFINE HSER_CLROERR 1".
    Then add the following 3 lines in your ISR:
    Code:
    For i = 0 to 127
            if RCSTA.1 = 1 then  'Add this line  "OERR: Overrun Error bit"
                lcdout $fe,1,"Overrun Error: ", dec3 i  'Add this line
            endif  'Add this line
            HSERIN [HEX2 H[i]]
        next I
    Doing this will let you know via your LCD if you are experiencing an overrun and at which byte position it occurred in.

    2. If you are experiencing overruns, then lower your baud rate to 2400 and see if the problem stops.
    Regards,
    TABSoft

Similar Threads

  1. Bluetooth headset for non bluetooth devices?
    By Normnet in forum Bluetooth
    Replies: 4
    Last Post: - 26th September 2015, 11:22
  2. USART SPI problem !
    By TripleS in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th October 2007, 22:09
  3. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  4. problem with USART
    By leemin in forum Serial
    Replies: 4
    Last Post: - 11th December 2006, 17:56
  5. PIC16F688 USART problem
    By Kees Reedijk in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 2nd October 2006, 04:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts