Activity Board <-> DNA-RTC board comms
Rsadeika
Posts: 3,837
in Propeller 1
I am having a heck of a time trying to set up a C program to get an Activity Board to talk to a DNA-RTC , two conversation. I have the small programs which I have been messing around with, but I cannot get them to cooperate like I want. Basically, I am not getting the expected string on the Activity Board side. Not sure what is going on here, it should be a very straight forward exercise. Anybody see how I can get this thing to work correctly?
Thanks
Ray
Activity Board
DNA-RTC board
Thanks
Ray
Activity Board
/* rb5x_ab_test.c */ #include "simpletools.h" #include "simpletext.h" #include "fdserial.h" serial *dna; int main() { // Add startup code here. /* Rx Tx BAUD */ dna = fdserial_open(1, 0, 0, 115200); // Connected to DNA-RTC board. char inBuff[40]; char inDna[40]; while(1) { // Add main loop code here. print("> "); // Test on terminal window getStr(inBuff,10); if(!strcmp(inBuff,"hour")) { writeStr(dna,"Time"); //pause(200); readStr(dna,inDna,10); //pause(150); print("%s",inDna); } else { print("Invalid Command\n"); } } }
DNA-RTC board
/* rb5x_test.c */ #include "simpletools.h" #include "simpletext.h" #include "fdserial.h" serial *ab; int main() { // Add startup code here. ab = fdserial_open(4, 5, 0, 115200); // Connected to Activity board //char inBuff[40]; int inInt; while(1) { // Add main loop code here. readStr(ab,inBuff,40); if(!strcmp(inBuff,"Time")) { writeStr(ab,"Got it!\n"); } //print("%s\n",inBuff); // Test to see if comm is there. //writeStr(ab,"A\n"); //pause(1000); } }
Comments
The way it is supposed to work, type in 'hour' on the Activity Board side, and the DNA-RTC is supposed to send "Got it!". All that I am getting is, a blank line as the response, on the AB side. Both programs compile, so whatever the problem is, it is very subtle, or I am just not seeing a glaring mistake.
Just to pick the program apart a bit, on the AB side, 'inDna' is supposed to have the string from the DNA-RTC side, now I cannot even figure out how to see what that value does contain. I tried printf(), with no success. I have verified that there is communication between the two boards, by having the DNA-RTC board send a char and the AB capturing and displaying it on the terminal window.
What I am trying to do is setup the DNA-RTC board to run a clock program, and then have the AB get the datetime values when needed. I had a larger program that I was running that did just that, but I noticed that I was not getting anything from the DNA-RTC board clock program, just zero values, so basically this is a debug session. Still scratching my head as to what the next should be.
Ray
1) fd_serial's buffer is empty (this would make it a non-blocking call, which would cause your program to fail in the way that it is failing)
2) Some delimeter (like a newline) is reached. Since that delimeter can't be changed via a parameter to the function, one would have to assume it is a newline. Since your program doesn't send a newline, the failure you're experiencing would also be expected in this scenario.
3) It waits for `max` chars to be sent. Since your program isn't sending 40 characters, I would once again expect to see the same failure you're experiencing.
Soooo.... good luck It could be any one of the three. You'll have to dig through the source code to figure out what makes readStr() stop reading, or wait for someone else to respond.
In these cases, it would be good to test the individual programs with something known to work, for example, connect one board to the PC with a USB-Serial plug and test the interaction with a terminal program, once that works, connect to the other board and do the same. Now connecting the two boards toghether should work.
Hope this helps.
I am now considering a bunch of steps backward, work in project manager part of SimpleIDE, and develop my own libraries as needed. But, when I started to do a lookup of where everything is at, source wise, not even sure where the official PropGCC source code is to be found. I make a point on OFFICIAL source code. Probably the very important library, to look at, would be propeller.h.
I have basically, I will call it wasted, a couple of days making some assumptions about the simpletools library, and finding out that it does not necessarily work the way you would think. Granted most of the simple functions work as assumed, but I am running into problems with other functions, very subtle problems. I fully realize that Parallax developed this for their Educational program, so I am not going negative on Parallax, just describing some problems that I am running into.
Anybody have any suggestions as to a good way to proceed with this?
Ray
I am genuinely curious if you would run into the same (or none, or just different) problems with PropWare. PropWare's Printer and Scanner interfaces are pretty simple and I hope they work quite intuitively (they're certainly intuitive for me :P ). You can even continue using FdSerial as your driver as shown in the example below. The example wraps FdSerial with PropWare's own interfaces, which I think (I really hope) don't cause you quite such a headache. (full source with comments)
(There's a problem with Doxygen at the moment that is making Printer's documentation fail to render. Reference the source directly for Printer docs in the meantime.
So, I guess I can say that, for whoever is still using SimpleIDE, in Help, the PropGCC reference(online), is no longer valid, or is it? And David brings up an excellent point about what version of PropGCC is bundled with your version of SimpleIDE. This is maddening enough to just switch over to command prompt PropGCC usage, but I do not think that I am there, just yet.
I will now investigate the PropGCC repo and see what is there, and maybe will have to bookmark it.
I still like the general simplicity of SimpleIDE, but it did find it somewhat cumbersome when you are trying to work with two Propeller boards. Opening and closing the projects is getting to be very annoying, let alone making the mistake of not pulling the cord on one board and overwriting the original program with another program, things get a little bit messy. If you have two cords, then you have to think about which COM port, was it COM3 or is it COM11. I am sure glad I do not do this for a living, I probably would have starved a long time ago. Saved by retirement, so basically I am not starving, just wasting a lot of time.
Ray
I have noticed that there are a lot of functions that were developed using spin2cpp, I like spin2cpp, but I am not sure if I like this added layer of complexity to trying to figure out why a function is not working the way it is supposed too. And if you notice, in the code below, there is use of readStr(), so what does that function tell you, or for that matter, what is it doing?
The worms are starting to multiply.
Ray
getStr uses the global variable dport_ptr to read the characters from, while readStr uses the port you specify with the text argument. It is the same difference between gets and fgets where gets uses the standard input and fgets a file descriptor passed as argument. I guess the global variable is used to communicate with the standard serial pins 31 and 30.
On too plan B, I will be implementing a softRTC program on the AB, and then see how far I get before I run out of memory on the AB. At least this way I can feel like I am accomplishing something useful. Maybe at some point I will have to add my Raspberry Pi 3, at least I can get the AB to talk to that device. If that works out then I can remove the softRTC code and get the datetime from the RPi. We shall see what happens.
Ray