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 CCS Technical Support

Function used but not defined

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



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

Function used but not defined
PostPosted: Tue Dec 22, 2015 8:16 am     Reply with quote

Hi,
Compiler 5.051

I use this in my code:

Code:
               while(tx_buffer_bytes(DEBUG_STREAM))
                  ;


To make sure that the last character is sent before I put the processor in sleep.
Otherwise the proc goes to sleep before last character is sent. Ofc I can put delay, but I want to be as efficient as possible. So I get the error:
Quote:
*** Error 112 "main.c" Line 59(1,1): Function used but not defined: ... tx_buffer_bytes 272 SCR=756

But I found the function prototype in 16F628A.h file on line 361.

Code:
_bif unsigned int16 tx_buffer_bytes(unsigned int8 stream);

_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Tue Dec 22, 2015 8:34 am     Reply with quote

It is only defined, if you setup #USE RS232 to use a tx buffer.

Otherwise it doesn't exist.

If you look at the entry for it under RS232 I/O, it says:

Quote:

tx_buffer_bytes()

When using transmit buffer, returns the number of bytes in buffer that still need to be sent.


Note the 'when using transmit buffer'.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Tue Dec 22, 2015 1:19 pm     Reply with quote

as a further comment to this, this function relates to the software buffer. If you are waiting to sleep, you need to wait for the hardware to finish sending. This is the TRMT bit in the hardware. You'd need to define this bit (#bit=getenv("BIT:TRMT") - for the first UART), and wait for this to go off.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue Dec 22, 2015 2:11 pm     Reply with quote

Thank you T. I thought this is the reason I get garbage data but apparently I was wrong. Something else is happening and I don't know what. This is an excerpt of the code:

Code:

#include <16f628A.h>
#fuses INTRC_IO, WDT, MCLR, NOPROTECT, BROWNOUT
#device *=16
#use delay(clock=4M)
#USE RS232 (UART1, BAUD=9600, STREAM=DEBUG_STREAM, ERRORS)
#byte OPTION = 0x181
#bit TRMT = getenv("BIT:TRMT")

#define DEBUG

#include "start_button.c"

void ChipInit(void);
void ButtonProcess(struct button_stat* p_butt);
void GoSleep();

THREAD(WakeUpTask)
{
   if(restart_cause() == WDT_FROM_SLEEP)
   {
      output_high(STARTER_LED);
      delay_ms(50);
      output_low(STARTER_LED);
   }
}

THREAD(ToggleStarterLed)
{
      output_toggle(STARTER_LED);
}


NEW_PROC(ToggleStarterLed);
NEW_PROC(WakeUpTask);

#INT_EXT
void ButtISR()
{
   PROC_POST(ToggleStarterLed);
}

void main(void)
{
int i;

ChipInit();
PROC_INIT(ToggleStarterLed);
PROC_INIT(WakeUpTask);

   while(TRUE)
   {

     
      for(i = 0; proc_list.p_proc[i] != 0; i++)
      {
         if(proc_list.p_proc[i] -> called == WAITING)
         {
            #IFDEF  DEBUG
               fprintf(DEBUG_STREAM, "%s\n", proc_list.p_proc[i] -> name);
               while(TRMT)
                  ;
                  delay_ms(20); //WHEN COMMENT THIS LINE PRINTS GARBAGE
            #ENDIF
            proc_list.p_proc[i]->func();
            proc_list.p_proc[i]->called = IDLE;
         }
      }
    restart_wdt();
    sleep();
   
    PROC_POST(WakeUpTask);
   }
}

void ChipInit(void)
{
   setup_oscillator(OSC_4MHZ);
   OPTION &= (~(1 << 7));
   StartButtonInit();
   SETUP_CCP1(CCP_OFF);
   ext_int_edge(0, H_TO_L);
   ENABLE_INTERRUPTS(INT_EXT_H2L);
   ENABLE_INTERRUPTS(GLOBAL);
   setup_wdt(WDT_2304MS);
 
}

When I press the button Interrupt H2L is trigered. It wakes up the chip and puts TASK in the queue. Then the FOR loop process all the tasks in the queue.
The function fprintf prints the names of the tasks that are being processed.
So the key thing here is in the delay_ms(20) function. When commented I get garbage string (only when wake up with BUTTON, H2L edge). When delay_ms(20) play, everything works as desired. It is possible to work with even shorter delay, and it might be not a problem for this application, but I am so curious what is really causing this behavior.
_________________
A person who never made a mistake never tried anything new.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue Dec 22, 2015 2:25 pm     Reply with quote

If more info needed here is the entire data: https://github.com/RadoslavMarinov/CCS/tree/c3a3573c308f61318b3282e9eecb56fec17ce5ff
_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Tue Dec 22, 2015 3:42 pm     Reply with quote

You have other code that is not shown to simulate multi-threading. I'd suspect that the thread queue has to be empty before the sleep.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue Dec 22, 2015 3:52 pm     Reply with quote

Everything is here https://github.com/RadoslavMarinov/CCS/tree/c3a3573c308f61318b3282e9eecb56fec17ce5ff
_________________
A person who never made a mistake never tried anything new.
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Tue Dec 22, 2015 5:12 pm     Reply with quote

I don't know your PIC very well, but on mine, a value of 1 means it is ready and 0 means wait. Normally I do the inverse of the check you do.

You have
Code:
while(TRMT);


I tend to use
Code:
while( !TRMT );


check your data sheet and make sure you are looping on the right value for that bit.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Mon Dec 28, 2015 12:52 pm     Reply with quote

Doesn't work either.
_________________
A person who never made a mistake never tried anything new.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Dec 28, 2015 1:09 pm     Reply with quote

hmm...
#bit TRMT = getenv("BIT:TRMT")

Maybe check the listing and confirm that TRMT is the correct bit of the correct register your program wants to see. Just because it compiles 'fine' doesn't mean it is correct. Depending on the compiler version, it might be looking at the wrong bit of a wrong register! Maybe the PIC device header info could be corrupted ?

At least if you check the listing and confirm this isn't the problem, well you'll have to look elsewhere.

jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Mon Dec 28, 2015 1:25 pm     Reply with quote

Try being explicit:

Code:

while (TRMT==FALSE)
    ;


It certainly ought to work, but I have seen problems on some compiler versions with using 'not' on a bit.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Sat Jan 02, 2016 11:32 am     Reply with quote

Ok it works now. I tried

Code:
while (TRMT==FALSE)


Then

Code:
while (!(TRMT))


Then

Code:
while (!TRMT)


And all of them work correct now. Maybe there was hardware problem. I don't know what has changed since last time. Sorry for wasting your time.
_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sat Jan 02, 2016 3:12 pm     Reply with quote

We have all had ones like that!...
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