CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

fat.c and i2c stream "Error#12 Undefined identifier

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

fat.c and i2c stream "Error#12 Undefined identifier
PostPosted: Fri Sep 28, 2018 9:21 am     Reply with quote

I am working on a project with the PIC16F19175 on version 5.078 of CCS.

In my code, I have set up RS232 UART, I2C, and some other peripherals and have them all working. I am now trying to also integrate an SD card into my project using mmcsd.c and fat.c. When #include ".\fat.c", my code suddenly does not compile, saying that my stream identifier for I2C is undefined. This happens whether I use the original <fat.c> or if I use the one from this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=53787

At this point, I am not yet concerned about any hardware hookups since the code does not even compile.

Here is the code that I feel is relevant:
Code:

#include <16F19175.h>
#include "PIC16F19175regs.h"
#DEVICE ADC=12
#use delay(clock=16000000)

#PIN_SELECT U2RX=PIN_B7
#PIN_SELECT U2TX=PIN_B6

#use rs232(baud=9600, UART2, bits=8, parity=N, stop=1, stream=PC, ERRORS)
#use i2c(MASTER, scl=PIN_E0, sda=PIN_E1, stream=dipSwitch, FORCE_SW)

#include <stdio.h>
#include <stdlib.h>

#define MMCSD_PIN_SCL     PIN_C3 //o
#define MMCSD_PIN_SDI     PIN_C4 //i
#define MMCSD_PIN_SDO     PIN_C1 //o
#define MMCSD_PIN_SELECT  PIN_A5 //o

#include ".\mmcsd.c"
#include ".\fat.c"


// In this function, dipSwitch is an undefined identifier
unsigned int dipReader()
{
    unsigned int ans = 0;
   
    disable_interrupts(GLOBAL);
    i2c_start(dipSwitch);
    i2c_write(dipSwitch, 0x41); 
    ans = (int8) i2c_read(dipSwitch, 1);
    ans = (int8) i2c_read(dipSwitch, 0);
    i2c_stop(dipSwitch); // stop the i2c stream
    enable_interrupts(GLOBAL);
    return ans;
}

int main(int argc, char** argv)
{
    while(1)
    {
        delay_ms(1000);
        fprintf(PC, "%u\r\n", dipReader());
    }

    return 0;
}


I get this error for every instance of "dipSwitch" in the i2c functions:
Code:

Error#12  Undefined identifier   dipSwitch


I can get away with not naming the stream in the i2c functions, but I would rather keep them there to make code easier to read in the future.

Does anybody have experience dealing with this problem? Why does the stream identifier break when I introduce fat.c?

I am fairly certain that it is fat.c that breaks the stream identifier. I have gotten rid of #use rs232 and I still get the same issue.

Please let me know if there is any other info that would help solve the issue. Thanks for your help.

ps. Before you ask, I am planning to use a SparkFun level translator between my 5V PIC and the SD card.
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Fri Sep 28, 2018 10:03 am     Reply with quote

Change the name.

Do a search for dipswitch. You'll probably find that the fat driver has a #define somewhere setting this to a value, so when used as a stream name, it is undefined as such....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 28, 2018 1:53 pm     Reply with quote

I investigated this and a duplicate name is not the problem.
I shortened the name to dipSw and I still got the error.

The two main facts are:

1. CCS is secretly promoting the mixed case stream name in the
#use i2c() statement to all caps. Putting a #case statement above
that line does not change this.

2. The fat.c file has a #case statement near the top.

This results in 'DIPSW' in the stream definition not matching 'dipSw' in
the i2c_start(DipSw) line and you get the error.

The solution is to use all caps for the stream name, everywhere in your
code. You could remove #case from fat.c, but potentially that would
cause other problems. It's easier to use DIPSW everywhere.

Test program:
Code:
#include <16F19175.h>
#use delay(internal=16M)
#use i2c(MASTER, scl=PIN_E0, sda=PIN_E1, stream=dipSw, FORCE_SW)

#case   // fat.c contains a #case statement here

//=======================================
void main()
{

i2c_start(dipSw);  // This causes an Undefined Identifier error

i2c_start(DIPSW);  // This compiles OK

while(TRUE);
}


After writing this up I searched for prior posts and found
this one in March 2018 by temtronic:
http://www.ccsinfo.com/forum/viewtopic.php?t=57063
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Sat Sep 29, 2018 2:12 am     Reply with quote

Yes this is odd.
I've always used upper case for stream names. Like defines. I remember that older post coming up, but hadn't 'filed it' as of interest, since I use upper case. Should have twigged in this one.
Well done PCM_programmer.
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Tue Oct 02, 2018 2:39 pm     Reply with quote

I see I'm getting replies from some prolific members :D

Yes, in my case, it seems like it is the #case in fat.c that is causing the issue.

I hadn't considered trying all caps before. After renaming the stream name with all caps, I can now use the stream name within the I2C functions.

Thanks for the help!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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