|
|
View previous topic :: View next topic |
Author |
Message |
peer9802
Joined: 26 May 2007 Posts: 14
|
CCS With OpenLog Device |
Posted: Tue Sep 23, 2014 7:32 pm |
|
|
I'm hoping someone can help me out with an issue I'm having. I purchased an OpenLog module for a process control/data recording project I've been playing around with. I can create files and log, to files, without any problems. The issue I'm having is reading data from the chip. I can see data being transferred on my o-scope; however, it's showing up as gibberish in the debug console (CCS V4.125).
Below is a code snippet. I've also tried using the RDA interrupt without any luck (it's been a few years since I've done anything with microcontrollers so my chances of incorrect implementation are pretty good).
Any help would be greatly appreciated.
Code: |
#include <18F4550.h>
#device ICD=TRUE
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL5 //Divide By 5(20MHz oscillator input)
#FUSES CPUDIV1 //No System Clock Postscaler
#FUSES HSPLL //High Speed Crystal/Resonator with PLL enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES DEBUG
#use delay(clock=48000000)
#USE I2C(MASTER, SCL=PIN_B0, SDA=PIN_B1, FORCE_SW, SLOW)
#USE SPI (MASTER, CLK=PIN_D6, DI=PIN_D7, /*ENABLE=PIN_D5,*/ MODE=0, BITS=16)
#use rs232(debugger, RCV=PIN_B3, XMIT=PIN_B3,STREAM=MONITOR)
#use rs232(baud=9600,parity=N,xmit=PIN_D0,rcv=PIN_D2, FORCE_SW, bits=8, STREAM=logger)
//gets the OpenLog device out of auto log mode
fputc(26, logger);
fputc(26, logger);
fputc(26, logger);
delay_ms(200);
//fprintf(logger, "new test3.csv\r\n"); //works fine
//fprintf(logger, "append test33.csv\r"); //works fine
c = 'r';
count=0;
fprintf(logger, "size test33.csv\r"); //attempt to get the file size
while(count<255)
{
if(kbhit(logger))
{
c = fgetc(logger);
fprintf(MONITOR, "%c", c);
}
delay_ms(1);
count++;
}
fprintf(MONITOR, "\n"); |
_________________ Eric |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 23, 2014 8:20 pm |
|
|
Read this thread about the debug monitor:
http://www.ccsinfo.com/forum/viewtopic.php?t=30627
Note that the CCS debugger routines in their IDE expect incoming
data at 2400 baud. According to that thread, you need to specify the
baud rate at 2400 for the debug monitor when using streams.
However, you have a larger problem than just configuring the debug
monitor. You have incoming data from your logger at 9600 baud.
But then, you want to re-transmit it to the CCS IDE debug monitor
which only runs at 2400 baud. So you're going to get overruns.
You're using software UARTs for both incoming and outgoing data.
Software UARTs "camp on" the i/o ports continuously while transmitting or
receiving a byte. While you're slowly sending out data to the IDE at
2400, you're missing incoming bytes. The CCS software can't handle
running two simultaneous soft UARTs. It's not designed to do it.
There are work-arounds. http://brushelectronics.com used to sell
software UART code for multiple soft UARTS running simultaneously but
I haven't seen it offered on his website for several years now.
Ttelmah posted an example of an interrupt-driven software UART in the
code library, but I think it only supports one channel. It's not hard to
make an interrupt-driven soft UART routine. I've done it too, but I've not
done multi-channels at different baudrates. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9240 Location: Greensville,Ontario
|
|
Posted: Wed Sep 24, 2014 5:15 am |
|
|
Another solution is to use a PIC with two hardware UARTs. Since you're not using the USB peripheral of the 4550, I'd suggest using the 46K22 or any PIC with hardware UARTS. It allows you to have 2 serial channels with proper interrupts, buffers, etc. that can easily run at 115k200.
Just another way to go.
and yes, I have a tube full of 4550s on my bench collecting dust.
jay |
|
|
peer9802
Joined: 26 May 2007 Posts: 14
|
|
Posted: Wed Sep 24, 2014 7:29 pm |
|
|
Thanks for the help!
I was using the UART pins for something else on my demo board so I took that device off and connected the OpenLog. I also removed the code which prints to the debug monitor and now display on a LCD.
Below is a snippet of my current code. I seem to be getting the correct response after I enter the three "26" commands but not after the "size" command. My file size is 5874 bytes (according to Matlab) though the returned string is "si" which does not seem to jive.
Any ideas?
Code: |
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7, bits=8, STREAM=logger )
char data[10];
count=0;
memset(data, 0x00, 10);
fputc(26, logger);
fputc(26, logger);
fputc(26, logger);
ii=0 ;
while(ii<65000)
{
if(kbhit())
{
c = getc();
data[i] = c;
i++;
}
delay_us(1);
ii++;
}
lcd_putc("\f");
lcd_gotoxy(1,1);
printf(lcd_putc, "r=%s", data);
delay_ms(2000);
//fprintf(logger, "new test3.csv\r\n");
//fprintf(logger, "append test33.csv\r");
c = 'r';
count=0;
memset(data, 0x00, 10);
fprintf(logger, "size test33.csv\r");
delay_ms(100);
ii=0;
i=0;
while(ii<65000)
{
if(kbhit())
{
c = getc();
data[i] = c;
//fprintf(MONITOR, "%c", c);
i++;
}
delay_us(1);
ii++;
}
lcd_putc("\f");
lcd_gotoxy(1,1);
for(i=0;i<5;i++)
{
printf(lcd_putc, "%d", data[i]);
} |
_________________ Eric |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Sep 24, 2014 10:10 pm |
|
|
Code: | fputc(26, logger);
ii=0 ;
while(ii<65000)
{
if(kbhit())
{
c = getc();
data[i] = c;
i++;
}
delay_us(1);
ii++;
} |
Where's the declaration of 'ii' ? Where is 'i' ever initialized to 0 ?
Quote: | #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7, bits=8, STREAM=logger ) |
The line above is missing the ERRORS parameter. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9240 Location: Greensville,Ontario
|
|
Posted: Thu Sep 25, 2014 3:49 pm |
|
|
One possible concern I have is that the OpenLog device is really a 3 V device and probably won't work with a 5V PIC.
While the datasheet says 3-12 V, there's an onboard 3V regulator for the micro and sd card.
something to consider ?
jay |
|
|
peer9802
Joined: 26 May 2007 Posts: 14
|
|
Posted: Thu Sep 25, 2014 6:07 pm |
|
|
Quote: | Where's the declaration of 'ii' ? Where is 'i' ever initialized to 0 ?
|
They are both just above the code I copied (i is also=0 above the second code block). ii is uint16.
Quote: | One possible concern I have is that the OpenLog device is really a 3 V device and probably won't work with a 5V PIC.
While the datasheet says 3-12 V, there's an onboard 3V regulator for the micro and sd card.
|
OpenLog is not documented extremely well so these are the things I'm trying to find out from people exerienced with this device. I wanted simple data logging and this device does that well. Reading from it is a bonus. _________________ Eric |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|
|
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
|