|
|
View previous topic :: View next topic |
Author |
Message |
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
rs232 problem with dat.net |
Posted: Thu Aug 24, 2017 4:03 am |
|
|
Hello,
My friend and i are working on a project and try to communicate via bluetooth.
I use 18f2550 and wrote this code:
Code: |
#include <18F2550.h>
#DEVICE ADC=10
#fuses INTRC_IO,NOWDT,MCLR,NOPROTECT,NOLVP,NODEBUG,NOBROWNOUT,CPUDIV1,VREGEN
#use delay(clock=8000000)
#use rs232(baud=9600, UART1, ERRORS,stream = bt)
void main()
{
delay_ms(1000);
while(true)
{
putc('a',bt);
delay_ms(1000);
}
}
|
I can see the 'a' letter on putty. I tried the alternative with printf instead of putc().
The problem is he can not get the data i send. The interesting part is he gets data successfully from Arduino. So does anyone know what might be difference on comm protocols between Arduino and PIC ?
Is there something wrong on my code ? Or is there an alternate way to send data besides printf or putc ?
Thank you so much.
Best wishes,
Doguhan
Note:
I tried the code with another version:
Code: |
#include <18F2550.h>
#DEVICE ADC=10
#fuses INTRC_IO,NOWDT,MCLR,NOPROTECT,NOLVP,NODEBUG,NOBROWNOUT,CPUDIV1,VREGEN
#use delay(clock=8000000)
#use rs232(baud=9600, UART1, ERRORS,stream = bt)
#use rs232(baud=9600, xmit=PIN_B1,stream = motormodul)
void main()
{
delay_ms(1000);
while(true)
{
printf("a");
delay_ms(1000);
}
} |
The problem at this version i cannot see the letter 'a'. PIC doesn't print anything. But if i add any input before the printing like if(kbhit(bt)) it starts to print data. So i assumed it cannot know from which stream to print. Am i right ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Thu Aug 24, 2017 4:52 am |
|
|
Since the first program does work in sending the 'a' to a PC running putty, I'd say it's probably a problem with the bluetooth module.
You should post a link to the datasheet of the exact module you're using. One thing I've seen is that today's 'devices and 'modules' generally tend to be 3 volt devices and they will NOT correctly work with 5 volts PIC if connected directly.
The next issue I see is NO BT initialization routines. I can't see how 2 BT devices can talk to each other without some form of 'setup' being necessary. There has to be some startup/init/setup code otherwise BT devices wouldn't know who and how to communicate with.
Does the receiving PIC pass the 1Hz LED test program ? I'd have both PICs flash an LED (toggle) for every pass of the loop.It's a simple 'I'm working' visual aid for us humans.
This is a case where we need a lot more information
Jay |
|
|
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
|
Posted: Thu Aug 24, 2017 5:46 am |
|
|
temtronic wrote: | Since the first program does work in sending the 'a' to a PC running putty, I'd say it's probably a problem with the bluetooth module.
You should post a link to the datasheet of the exact module you're using. One thing I've seen is that today's 'devices and 'modules' generally tend to be 3 volt devices and they will NOT correctly work with 5 volts PIC if connected directly.
The next issue I see is NO BT initialization routines. I can't see how 2 BT devices can talk to each other without some form of 'setup' being necessary. There has to be some startup/init/setup code otherwise BT devices wouldn't know who and how to communicate with.
Does the receiving PIC pass the 1Hz LED test program ? I'd have both PICs flash an LED (toggle) for every pass of the loop.It's a simple 'I'm working' visual aid for us humans.
This is a case where we need a lot more information
Jay |
Hello Jay
I explained wrong. My code is uploaded to pic. My friends writes a software that uses unity game engine. There is not another pic. I am talking about one pic to computer communication.
The module is hc-05.
Thank you so much! |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Thu Aug 24, 2017 6:51 am |
|
|
In the putc version you had only one uart defined and called out the stream name. In the printf version you have two uarts defined and did not use the stream. With more than one uart you should use the stream to define which uart the data is being sent to.
Use fprintf(bt,"a") and I think you will have better results. |
|
|
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
|
Posted: Thu Aug 24, 2017 7:18 am |
|
|
gaugeguy wrote: | In the putc version you had only one uart defined and called out the stream name. In the printf version you have two uarts defined and did not use the stream. With more than one uart you should use the stream to define which uart the data is being sent to.
Use fprintf(bt,"a") and I think you will have better results. |
Thank you so much! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|