View previous topic :: View next topic |
Author |
Message |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
Function used but not defined |
Posted: Tue Dec 22, 2015 8:16 am |
|
|
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: 19499
|
|
Posted: Tue Dec 22, 2015 8:34 am |
|
|
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: 19499
|
|
Posted: Tue Dec 22, 2015 1:19 pm |
|
|
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
|
|
Posted: Tue Dec 22, 2015 2:11 pm |
|
|
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
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Tue Dec 22, 2015 3:42 pm |
|
|
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
|
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1345
|
|
Posted: Tue Dec 22, 2015 5:12 pm |
|
|
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
I tend to use
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
|
|
Posted: Mon Dec 28, 2015 12:52 pm |
|
|
Doesn't work either. _________________ A person who never made a mistake never tried anything new. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Mon Dec 28, 2015 1:09 pm |
|
|
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: 19499
|
|
Posted: Mon Dec 28, 2015 1:25 pm |
|
|
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
|
|
Posted: Sat Jan 02, 2016 11:32 am |
|
|
Ok it works now. I tried
Code: | while (TRMT==FALSE) |
Then
Then
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: 19499
|
|
Posted: Sat Jan 02, 2016 3:12 pm |
|
|
We have all had ones like that!... |
|
|
|