|
|
View previous topic :: View next topic |
Author |
Message |
gomond
Joined: 05 Nov 2008 Posts: 18
|
CCS LCD Drvr wont Co Exist with Brush Electr SDCARD Driver |
Posted: Thu Sep 24, 2009 5:25 am |
|
|
Hi I'm a bit of a newbie and I am using the Brush SD Driver to build a solar datalogger and I am trying to use the supplied CCS LCD driver and the Brush Electronics SD Card driver together on a Futurlec ET BASE 8722 board.
The LCD driver works fine on the board and I can write to it.
The SD Card Driver also works great, but if I try to use both together it just hangs on lcd_init().
I am using the lcd on port H so there are no conflicts.
Just a small snippet.
|
\|/
Code: |
/********************************/
#ifdef ETBASE_8722
#include <LCD.C>
#define LCD_ENABLE_PIN PIN_H3 ////
#define LCD_RS_PIN PIN_H1 ////
#define LCD_RW_PIN PIN_H2 ////
#define LCD_DATA4 PIN_H4 ////
#define LCD_DATA5 PIN_H5 ////
#define LCD_DATA6 PIN_H6 ////
#define LCD_DATA7 PIN_H7
#endif
/********************************/
void main ()
{
int i;
FRESULT FS_Status;
disable_interrupts(GLOBAL);
restart_wdt();
init_pic();
lcd_init();
// setup Status LED Toggle counter
StatusLEDCount = CStatusLEDCount;
#ifdef LED_Status
bit_clear(LED_Status);
#endif
TMR_Activity = CTMR_Activity;
// send an "I'm alive" LED toggle
#ifdef LED_Health
for (i=0; i<5; i++)
{
bit_set(LED_Health);
delay_ms(300);
bit_clear(LED_Health);
delay_ms(300);
}
#endif
// initialise hardware uart (console) receive buffer pointers
RxHeadC = 0;
RxTailC = 0;
// initialise the iterrupts
// this will intialise both the global and priority interrupts
clear_interrupt(INT_RDA);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
// initilise Console Command Buffer Pointer
CntCmdC = 0; // initialise number of characters in the command buffer
// initialise the real time clock
init_rtc();
//! lcd_putc("\fAlive N Kicken");
printf("\r\n\r\nMMC/SD/SDHC Datalogger\r\n%s %s %s\r\n\r\n",\
"Version 1.0 - compiled", __DATE__,__TIME__);
// initialise the media and filesystem
// this will loop until the card is found
do
{
FS_Status = f_mountdrv();
if (FS_Status)
{
display_file_result(FS_Status);
#ifdef LED_Status
bit_set(LED_Status);
#endif
delay_ms(500);
#ifdef LED_Status
bit_clear(LED_Status);
#endif
delay_ms(500);
}
}
while (FS_Status);
printf("For help type ?\r\nCMD>");
for (;;)
{
ServiceSystemTimer();
ServiceRxQ();
Service_Analog_Inputs();
}
}// End of main()... |
|
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Thu Sep 24, 2009 10:16 pm |
|
|
I posted a reply yesterday but for some reason it is no longer here. I do not know why the LCD init fails. Try moving the LCD init to after the hello message is printed to the serial port.
There was no schematic on Futurlec's site so I could not see if there was a hardware conflict.
There is no SD/MMC card on the Futurlec board, how did you connect the card?
How did you do the level conversion from the 5 volt PIC to the 3.3v SD card?
Do you have a pull-up resistor on DO out of the card?
What port did you use for the SD/MMC chip select? _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
gomond
Joined: 05 Nov 2008 Posts: 18
|
|
Posted: Fri Sep 25, 2009 1:10 am |
|
|
Thanks Andrew
I have emailed you the schematics as I am unsure how to attach them here.
I have the LCD on PORT H in nibble mode, and the SDCARD on PORT C entirely, CS as well on C2.
The level translation is done using your example with the divider network & the pullups are on the card adapter (jumper selectable).
The LCD functions perfectly using any of the test programs that I use.
And Your code also functions flawlessly on it.
I only run into trouble when I perform an lcd_init() within your example CCS PCH FATC
I have moved the init all around so as to try to track down the conflict.
I placed it inside init_pic() as well.
I know that it will turn out to be something dumb that I may have done but I haven't done much, as your example program is almost exactly what I needed anyway. Just wanted to log some data from 4 analog inputs to the sdcard every 1 second or so in csv, and have an lcd for status eg: FS space left etc.
Here is the excerpt from platform.h
(By the way the SD library is excellent and it is the first time I have ever bought something like this that worked out of the box).
Code: |
#ifdef ETBASE_8722
#include <18F8722.h>
#device adc=11
#fuses NOWDT,WDT128, H4, NOPROTECT, NOIESO, BROWNOUT, PUT, STVREN
#fuses DEBUG, NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#build(reset=0x00:0x07)
#org 0x01e000, 0x01ffff {}
// base frequency
// When setting the XTAL_FREQ
// the SPI interface must be configured for a SPI CLK >=8MHz and <=10MHz
// Errata ENC28J60 Rev B1 sets minimum SPI clock of 8MHz
#define XTAL_FREQ 40000000 // OSC freq in Hz
#use delay(clock=XTAL_FREQ)
//#use rs232(baud=115200,UART1,parity=N,bits=8,errors, STREAM=COM1)
//#use rs232(baud=115200,UART2,parity=N,bits=8, STREAM=COM2)
#use rs232(baud=115200,UART1,parity=N,bits=8)
#define SWU_Tx LATC, 1 // define the transmit pin for the SW UART
#define SWU_Rx PORTC, 2 // define the receive pin for the SW UART
// Define I/O default port data and TRIS parameters
#define PA_DefData 0b00000000
#define PA_DefTRIS 0b00010001
// 7 not used
// 6 not used
// 5 Status LED Output
// 4 Release push button input
// 3 not used
// 2 not used
// 1 not used
// 0 Analog Source
#define PB_DefData 0b00001000
#define PB_DefTRIS 0b00000011
// 7 not used
// 6 not used
// 5 Busy LED output
// 4 Health LED Output
// 3 FRAM_CS FM25256
// 2 not used
// 1 WOL ENC28J60 Ethernet Controller
// 0 INT ENC28J60 Ethernet Controller
#define PC_DefData 0b00000001
#define PC_DefTRIS 0b10010000
// 7 RX Serial
// 6 TX Serial
// 5 SDO
// 4 SDI
// 3 SCK
// 2 CS for SD_Card
// 1
// 0
#define PD_DefData 0b00000111
#define PD_DefTRIS 0b00000000
// 7
// 6
// 5
// 4
// 3
// 2
// 1 ENC_CS ENC28J60 Ethernet Controller
// 0 RESET ENC28J60 Ethernet Controller
#define PE_DefData 0b00000000
#define PE_DefTRIS 0b11111111
// 7 not used
// 6 not used
// 5 not used
// 4 not used
// 3 not used
// 2 not used
// 1 not used
// 0 not used
#define PF_DefData 0b00000000
#define PF_DefTRIS 0b11111111
// 7 not used
// 6 not used
// 5 not used
// 4 not used
// 3 not used
// 2 not used
// 1 not used
// 0 not used
#define PG_DefData 0b00000010
#define PG_DefTRIS 0b11111101
// 7 not used
// 6 not used
// 5 not used
// 4 not used
// 3 not used
// 2 RX Serial - COM2 also wired to RB1
// 1 TX Serial - COM2 also wired to RB2
// 0 not used
#define PH_DefData 0b00000000
#define PH_DefTRIS 0b11111111
// 7 not used
// 6 not used
// 5 not used
// 4 not used
// 3 not used
// 2 not used
// 1 not used
// 0 not used
#define PJ_DefData 0b00000000
#define PJ_DefTRIS 0b11111111
// 7 not used
// 6 not used
// 5 not used
// 4 not used
// 3 not used
// 2 not used
// 1 not used
// 0 not used
// define ADC control register sttings for ADCON1
//#define PADC_Def 0b10001110 // disable analog inputs except AN0
#define LED_Busy LATB, 5 // Busy LED (SD/MMC) - high to illumuniate
#define LED_Status LATB, 3 // Status LED - high to illumuniate
#define LED_Health LATB, 4 // Health LED - high to illumuniate
#define Release PORTA, 4 // Key Switch input (normally high)
// define Ethernet Controller control inputs and outputs
#define ENC_CS LATD, 1 // ENC chip select (active low)
#define ENC_INT LATB, 0 // ENC INT (active low)
#define ENC_WOL LATB, 1 // ENC Wake on LAN interrupt (active low)
#define ENC_RESET LATD, 0 // ENC RESET active low
// define SD/MMC control
//#define MMC_CS LATD, 3 // MMC Chip Select Active low
#define SD_CS LATC, 2 // MMC Chip Select Active low
// define FRAM control
#define SPI_Setup 0x20
#endif
|
|
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Fri Sep 25, 2009 2:02 am |
|
|
Unfortunately the schematic was unreadable. I could not read it at any magnification.
There is a hardware bug in their level converter but seeing as you are using the resistor approach it is of no interest.
I think I see the problem, you were too aggressive in commenting out the PADC_Def line. This line is used to setup the ADCCON1 register to determined which ports should be configured for digital I/O versus analog
Code: | //#define PADC_Def 0b10001110 // disable analog inputs except AN0 |
This means the analog inputs are not being disabled on inputs shared with digital I/O including port H. You either need the set the PADC_Def to the correct value or you need to use a CCS setup_adc functions to setup the analog ports. The correct place to do this is in init_pic(). _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
gomond
Joined: 05 Nov 2008 Posts: 18
|
|
Posted: Fri Sep 25, 2009 2:36 am |
|
|
I thought that this would be correct?
///////////////////////////////////////////////////////////////////////////
// void init_pic(void)
//
// Initialise the hardware defaults
///////////////////////////////////////////////////////////////////////////
{
// setup_adc_ports
setup_adc(ADC_CLOCK_INTERNAL); <-------
setup_adc_ports(AN0_TO_AN4); <--------
setup_spi(FALSE);
setup_wdt(WDT_OFF);
#ifdef PCmp_Def
// setup_comparator
CMCON = PCmp_Def; // initialise comparators
#endif
-----------------------
Thats why I commented out the
//#define PADC_Def 0b10001110 // disable analog inputs except AN0
????? |
|
|
gomond
Joined: 05 Nov 2008 Posts: 18
|
|
Posted: Fri Sep 25, 2009 3:41 am |
|
|
Andrew
I have been placing debug printfs into LCD.C and found that the hang occurs after the first iteration of lcd_send_byte(0,LCD_INIT_STRING[i]);
Which would have me thinking that it is failing lcd_read_byte();
but lcd.c does all the tris blagh automagicaly ????? or not ????
I am starting to think that I should stick to Farming!. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Fri Sep 25, 2009 8:57 am |
|
|
gomond wrote: | I thought that this would be correct?
///////////////////////////////////////////////////////////////////////////
// void init_pic(void)
//
// Initialise the hardware defaults
///////////////////////////////////////////////////////////////////////////
{
// setup_adc_ports
setup_adc(ADC_CLOCK_INTERNAL); <-------
setup_adc_ports(AN0_TO_AN4); <--------
setup_spi(FALSE);
setup_wdt(WDT_OFF);
#ifdef PCmp_Def
// setup_comparator
CMCON = PCmp_Def; // initialise comparators
#endif
-----------------------
Thats why I commented out the
//#define PADC_Def 0b10001110 // disable analog inputs except AN0
????? |
Yes - this is correct. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Fri Sep 25, 2009 9:04 am |
|
|
Have you added this to you code?
Code: | #define LCD_DATA_PORT getenv("SFR:PORTH") |
_________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
gomond
Joined: 05 Nov 2008 Posts: 18
|
2 hours this morning rounding up sheep fixed it. |
Posted: Fri Sep 25, 2009 7:17 pm |
|
|
I'm a dill...
The First issue was the order in which I placed the defines.
The constants were not parsed before the lcd.c was processed
(obvious later).
Code: | #ifdef ETBASE_8722
#include <LCD.C> <----------- Moved to just above #endif
#define LCD_DATA_PORT getenv("SFR:PORTH") <---introduced a new bug (see below).
#define LCD_ENABLE_PIN PIN_H3 ////
#define LCD_RS_PIN PIN_H1 ////
#define LCD_RW_PIN PIN_H2 ////
#define LCD_DATA4 PIN_H4 ////
#define LCD_DATA5 PIN_H5 ////
#define LCD_DATA6 PIN_H6 ////
#define LCD_DATA7 PIN_H7
#endif
|
After the #define LCD_DATA_PORT getenv("SFR:PORTH") was added I had a new error.
Undefined Identifier BIT_TEST
(it is in the wrong case! (CCS example Bug))
The following lines in the CCS LCD.C file had to be changed to:
Code: |
output_bit(LCD_DATA4, bit_test(n, 0));
output_bit(LCD_DATA5, bit_test(n, 1));
output_bit(LCD_DATA6, bit_test(n, 2));
output_bit(LCD_DATA7, bit_test(n, 3));
|
Now all is working like a charm.
Thank you Andrew very much for your help and I am sorry for wasting all your time. |
|
|
|
|
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
|