Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 22:31 17 Sep 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Machine code for SetPin 2,din

     Page 2 of 3    
Author Message
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1629
Posted: 06:02am 03 May 2015
Copy link to clipboard 
Print this post

  G8JCF said  
Has anybody else experienced what @rogersan is going through ?

Peter


No. No problems!
causality ≠ correlation ≠ coincidence
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 04:00pm 03 May 2015
Copy link to clipboard 
Print this post

I'm still using MPLAB X IDE v2.05, from what @RogerSan has told me, the current version of MPLab/X is very different - to the extent that the Tutorials document is not good enough.

I'm not going to upgrade my MPLab/X because the version works, and works very well, so, I can't reproduce @rogersan's issues, hence why I would be very interested to hear from anyone who has the latest version of MPLab/X+XC32 installed please.

Many thanks

Peter
The only Konstant is Change
 
rogersan
Regular Member

Joined: 10/04/2015
Location: Australia
Posts: 79
Posted: 04:17pm 03 May 2015
Copy link to clipboard 
Print this post

I am uninstalling MPLAB X v3.3 and now installing v2.35. I will work through Peter's tutorial with that version to see if I can get an error free build.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1629
Posted: 10:41pm 03 May 2015
Copy link to clipboard 
Print this post

  G8JCF said   I'm still using MPLAB X IDE v2.05, ...

I'm not going to upgrade my MPLab/X because the version works, and works very well,


V2.35 works also well. I'm through Peter's tutorial without any issues. Thanks Peter!

I installed my MPLab/X+XC32 on a virtual machine (VirtualBox).

Michael
causality ≠ correlation ≠ coincidence
 
rogersan
Regular Member

Joined: 10/04/2015
Location: Australia
Posts: 79
Posted: 11:24pm 03 May 2015
Copy link to clipboard 
Print this post

I tried MPLAB X V2.35 but still got errors on the build, the -fPIC- mono -abicalls was not recognised. Perhaps the XC32 compiler version is causing problems.

I have sent the output of the build to Peter.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1629
Posted: 12:03am 04 May 2015
Copy link to clipboard 
Print this post

I'm using MPLAB X V2.35 with xc32-v1.33-full-install-windows-installer.exe
causality ≠ correlation ≠ coincidence
 
rogersan
Regular Member

Joined: 10/04/2015
Location: Australia
Posts: 79
Posted: 12:21am 04 May 2015
Copy link to clipboard 
Print this post

I am using MPLAB X V2.35 with XC32-v1.34 free version. The build does not recognise the -fPIC options. If you like I can send you the results of the build if you give me your Email address.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1629
Posted: 01:17am 04 May 2015
Copy link to clipboard 
Print this post

  rogersan said   I am using MPLAB X V2.35 with XC32-v1.34 free version. The build does not recognise the -fPIC options. If you like I can send you the results of the build if you give me your Email address.

No, thanks! Peter is the expert. I'm also a Newbie in this matter. In your place I would check it step by step. It works!

Michael
causality ≠ correlation ≠ coincidence
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 08:33am 04 May 2015
Copy link to clipboard 
Print this post

Hi Roger

The problem is that you need to enter for additional options


-fPIC -mno-abicalls


That is -fPIC space -mno-abicalls where -mno-abicalls is all one word

In your email you sent me the compiler output shows that you have entered


-fPIC -mno -abicalls


notice that you entered -mno space -abicalls



"C:\Program Files (x86)\Microchip\xc32\v1.34\bin\xc32-gcc.exe" -g -x c -c -mprocessor=32MX170F256B -MMD -MF build/default/production/main.o.d -o build/default/production/main.o main.c -fPIC -mno -abicalls
cc1.exe: error: unrecognized command line option "-mno"
nbproject/Makefile-default.mk:105: recipe for target 'build/default/production/main.o' failed
cc1.exe: error: unrecognized command line option "-abicalls"


Please re-enter -fPIC -mno-abicalls

OK ?

Hopefully that'll be you on your way starting to write CFunctions

Edit : I've just installed MPLAB X IDE v3.00.02 beta and XC32 v1.34 on another Windows 7 computer, and the tutorial regarding installing and checking out that your MPLAB/X installation and configuration is correct does fully apply, eg there is most definitely an Additional Options text entry box for XC32-gcc under project properties.

PeterEdited by G8JCF 2015-05-05
The only Konstant is Change
 
rogersan
Regular Member

Joined: 10/04/2015
Location: Australia
Posts: 79
Posted: 09:02am 05 May 2015
Copy link to clipboard 
Print this post

To Matherp

Do you have an Assembly Language listing of your dht11conv CFunction? I tried doing it again using your C code, and initially got a CFunction twice as long, Peter used Level 3 optimisation and got to about the same length as yours but still different. Perhaps this normal as there are different ways to do the same thing.

Do you remember what level of optimisation you used?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10406
Posted: 09:21am 05 May 2015
Copy link to clipboard 
Print this post


long long dht11conv(unsigned int *portname,long long *mypin,long long log[]){
unsigned int k,j;
#define mytmr1con *(volatile unsigned int *)0xbf800600 //timer 1 configuration register
#define mytmr1 *(volatile unsigned int *)0xbf800610 //timer 1 counter
unsigned int volatile * myport;
if(*portname==0) myport=(volatile unsigned int *)0xbf886020;
if(*portname==1) myport=(volatile unsigned int *)0xbf886120;
if(*portname==2) myport=(volatile unsigned int *)0xbf886220;
mytmr1con=0x8030; //turn on with scale 256
j=1<<*mypin;
while (((*myport&j)!=0) && (mytmr1<60000)); //wait for low while dht processes
if(mytmr1>=60000) return -1;
mytmr1con=0x8010; //rescale 8
mytmr1=0;
while (((*myport&j)==0) && (tmr1<40000)); //wait for the next high
if(mytmr1>=40000) return -1;
mytmr1=0; //reset the timer
while (mytmr1<40000){
while (((*myport&j)!=0) && (mytmr1<40000)); //wait for low
log[k]=mytmr1;
if (mytmr1<40000){
mytmr1=0;
k++;
}
while (((*myport&j)==0) && (mytmr1<40000)); //wait for the next high
if (mytmr1<40000) mytmr1=0; //valid pulse so reset timer
if (k==41) break;
}
return j;
}


Compile this code O1 and you will get identical Cfunction. Use v1.33 compiler, 1.34 has bugs.

Note I've changed variable i to k to stop the BB corrupting the code (it doesn't like "open-square-bracket i close-square-bracket"
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 09:24pm 05 May 2015
Copy link to clipboard 
Print this post

  twofingers said   I'm using MPLAB X V2.35 with xc32-v1.33-full-install-windows-installer.exe

I've just done the same using Win7/64 for V2.35 and V1.33 as above without problems. Seems to follow Peter's (G8JCF) instructions and compiler setup nicely.

Greg
 
rogersan
Regular Member

Joined: 10/04/2015
Location: Australia
Posts: 79
Posted: 10:01pm 05 May 2015
Copy link to clipboard 
Print this post

I am going OK now that the -fPIC -mono-abicalls problem has been fixed. I am still a bit puzzled as to which main.c program is being compiled when you build.

If you have more than one project in MPLAB X, you can have more than one main.c. Hopefully a build compiles the one which is high lighted. I have tried creating a new project for each new version of the program but this should not be necessary.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10406
Posted: 10:30pm 05 May 2015
Copy link to clipboard 
Print this post

  Quote  I have tried creating a new project for each new version of the program but this should not be necessary.


For basic Cfunctions I use a single project with all of the individual functions I have created included in it.

It has a dummy "main" function as below:

void main(){}

Then I just select the individual function I'm working on in CfuncGen4PIC32 to create the specific Basic file.

 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 03:46am 06 May 2015
Copy link to clipboard 
Print this post

@RogerSan

If you have more than ONE project in MPLab/X, U MUST use menu Run | Set Main Project to designate which is the MAIN project to MPLab/X, MPlab/X will then set BOLD for the MAIN project in the left hand pane.

The MAIN project is the one which MPLab/X will build when you click the blue hammer. All and every .c file in the tree under the MAIN project will be part of the build. For CFunctions it is quite rare to have more than a single .c file, usually called main.c.

Peter
The only Konstant is Change
 
rogersan
Regular Member

Joined: 10/04/2015
Location: Australia
Posts: 79
Posted: 10:50pm 11 May 2015
Copy link to clipboard 
Print this post

CFunction causes CPU Exception #7 (bus error on load or store) in CFunction at address 0x0058.

I added to the dht11conv CFunction to set the bit in the data direction register (using TRISxSET), so the the pin connected to the DHT11 goes high during the CFunction.

Has anyone had this error in a CFunction?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10406
Posted: 10:57pm 11 May 2015
Copy link to clipboard 
Print this post

If you post the modified Cfunction I'll have a look at it. Use a zip file to avoid the BB corrupting it
 
rogersan
Regular Member

Joined: 10/04/2015
Location: Australia
Posts: 79
Posted: 11:24pm 11 May 2015
Copy link to clipboard 
Print this post

Here is the code, to zip it do I need to paste into hyperterminal (or similar) first?

/*
* File: main.c
* Author: user
*
* Created on 6 May 2015, 12:20 PM
*/
long long dht11convppm(unsigned int *portname, long long *mypin, long long log[]){

unsigned int k,j;
#define mytmr1con *(volatile unsigned int *)0xbf8006000 //timer 1 config reg
#define mytmr1 *(volatile unsigned int *)0xbf800610 //timer 1 counter

unsigned int volatile * myport;
unsigned int volatile * setport;


if(*portname==0) myport=(volatile unsigned int *)0xbf886020;

if(*portname==1) myport=(volatile unsigned int *)0xbf886120;

if(*portname==2) myport=(volatile unsigned int *)0xbf886220;

if(*portname==0) setport=(volatile unsigned int *)0xbf886018;

if(*portname==1) setport=(volatile unsigned int *)0xbf886118;

if(*portname==2) setport=(volatile unsigned int *)0xbf886218;

mytmr1con=0x8030; //turn on with scale 256

j=1<<*mypin;

*setport=j; // the pin is now an input, goes high

while (((*myport&j)!=0) && (mytmr1<60000)); //wait for low while dht processes

if(mytmr1>=60000) return -1;

mytmr1con=0x8010; //rescale 8

mytmr1=0;

while (((*myport&j)==0) && (mytmr1<40000)); //wait for the next high

if(mytmr1>=40000) return -1;

mytmr1=0; //reset the timer

while (mytmr1<40000){

while (((*myport&j)!=0) && (mytmr1<40000)); //wait for low

log[k]=mytmr1;

if (mytmr1<40000){

mytmr1=0;

k++;

}

while (((*myport&j)==0) && (mytmr1<40000)); //wait for the next high

if (mytmr1<40000) mytmr1=0; //valid pulse so reset timer

if (k==41) break;

}

return j;

}
main(){}
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 02:25am 12 May 2015
Copy link to clipboard 
Print this post

@RogerSan

One observation I would make is that the first of the arguments to the function is incorrectly specified, ie it should be

long long dht11convppm(long long *portname, long long *mypin, long long log[]){


Also, what Optimization level are you compiling with ? this is so that we can look at the disassembly and see which instruction has caused the bus exception.

edit re zip files: do a right click on the source file and select send to compressed file to make a .zip file

PeterEdited by G8JCF 2015-05-13
The only Konstant is Change
 
rogersan
Regular Member

Joined: 10/04/2015
Location: Australia
Posts: 79
Posted: 02:44am 12 May 2015
Copy link to clipboard 
Print this post

I used Optimization level 1.

Regarding the arguments for the function, you are right. I think I just used the code I was given for dth11conv, so I am not sure if it worked for that function.

Thanks for looking at the problem, I do not know how to find which line of code is causing the problem. I suspect it is
*setport=j;
 
     Page 2 of 3    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025