PDA

View Full Version : usart-bluetooth problem



murat44
- 30th December 2014, 07:01
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

HenrikOlsson
- 30th December 2014, 08:15
Hi,
1) Start by getting your serial comms working without interrupt. Then add the interrupt capabillity later.


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 (http://www.picbasic.co.uk/forum/showthread.php?t=19594).

/Henrik.

murat44
- 30th December 2014, 08:31
thank you for your answer hendrik. do i need to put "pause" in main routine in order to see blinking of led?

HenrikOlsson
- 30th December 2014, 08:36
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.

murat44
- 30th December 2014, 15:02
henrik, i did what you said but nothing has changed- neither led nor data. what do you think? can it be about hardware?

HenrikOlsson
- 30th December 2014, 15:27
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.....

murat44
- 1st January 2015, 09:16
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...


'************************************************* ***************
'* 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

aratti
- 1st January 2015, 10:49
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.

Charlie
- 1st January 2015, 16:46
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.

amgen
- 1st January 2015, 18:49
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

amgen
- 1st January 2015, 19:12
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


76247625

murat44
- 7th January 2015, 19:53
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...


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

Tabsoft
- 8th January 2015, 02:19
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,

murat44
- 8th January 2015, 20:25
no change :(

Tabsoft
- 8th January 2015, 23:57
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

Charlie
- 9th January 2015, 13:55
I repeat...

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.

murat44
- 9th January 2015, 15:38
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 :)


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

7669

Tabsoft
- 9th January 2015, 21:28
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.

murat44
- 10th January 2015, 13:31
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...

murat44
- 26th January 2015, 09:11
thank you all. everything works fine now :)

murat44
- 2nd February 2015, 16:48
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...

HenrikOlsson
- 2nd February 2015, 16:56
Provided all values are represented as two hexadecimal characters:


For i = 0 to 127
HSERIN[HEX2 DataIn[i]]
NEXT


/Henrik.

murat44
- 3rd February 2015, 09:24
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?

HenrikOlsson
- 3rd February 2015, 10:39
> 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.

murat44
- 3rd February 2015, 12:25
7707




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...

Tabsoft
- 3rd February 2015, 14:03
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.

HenrikOlsson
- 3rd February 2015, 14:27
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?



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

HenrikOlsson
- 3rd February 2015, 15:33
I just verified the method here and it works just fine, with 128 values.
Here's the code I used:

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:

7708

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.

Tabsoft
- 3rd February 2015, 18:28
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.

murat44
- 4th February 2015, 17:44
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:

7710

eeprom:24c512

HenrikOlsson
- 4th February 2015, 19:54
You're going to have to post your code so we can see what you're doing.

murat44
- 5th February 2015, 04:51
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...

Tabsoft
- 5th February 2015, 18:00
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:


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.