Shop OBEX P1 Docs P2 Docs Learn Events
How can write a two serial channels communication in propeller using Prop C — Parallax Forums

How can write a two serial channels communication in propeller using Prop C

KevinKKKevinKK Posts: 27
edited 2013-10-07 15:03 in Propeller 1
I am tying to let my project can open two serial ports , one is debug port (for my PC), the other is pin0 (RX) pin1 (TX) for another microcontroller.
But the results is the second port can't work. Should I create one cog for the second serial device ?

Here is my code :
test1007 (1).c.

#include "simpletools.h" // Include simple tools
#include "servo.h"
#include "ping.h"
#include "fdserial.h"
#include "simpletext.h"

void adder(void *par); // Forward declaration
static volatile int t, cmDist; // Global vars for cogs to share
unsigned int stack[40 + 25];

int main() // Main function
{
int cmd ;
int cog = cogstart(&adder, NULL, stack, sizeof(stack));
serial_close(simpleterm_pointer());
fdserial *rcv = fdserial_open(31, 30, 0, 9600); // serial port
fdserial *pololu = fdserial_open(0, 1, 0, 9600); // serial port
while (1) {
cmd = fdserial_rxTime(rcv,50);
dprint(rcv,"cmDist = %d \n", cmDist);
pause(50);
if (cmd == -1)
dprint(rcv, "\n Time Out");
else if (cmd == 48) {
dprint(rcv,"\n Typed cmd = 48");
fdserial_txChar(pololu,255);
fdserial_txChar(pololu,0);
fdserial_txChar(pololu,150);
pause(2000);
dprint(rcv,"\n stop");
fdserial_txChar(pololu,255);
fdserial_txChar(pololu,0);
fdserial_txChar(pololu,127);
}

} //while loop
}

void adder(void *par) // adder keeps going on its own
{

while(1) // Endless loop
{
cmDist = ping_cm(15); // Get cm distance from Ping)))


pause(200);
}
}
Sign In or Register to comment.