Mikroc, compile issues with 24bit adc code.

Thread Starter

house91320

Joined Feb 8, 2012
5
I'm having some issues with some code than i can figure out, anyone have any ideas?

72 1506 Implicit conversion of pointer to int MyProject.c
73 307 Illegal typecast 'can not convert to pointer' '' MyProject.c
73 1508 Implicit conversion of int to ptr MyProject.c
74 1506 Implicit conversion of pointer to int MyProject.c
82 402 ; expected, but 'SPI2_read' found MyProject.c
82 393 'SPI2_read' Identifier redefined MyProject.c



Code: Select all
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
long SPDR, PINB, PB4, SPSR, SPIF;
unsigned long buffer1;
unsigned long buffer2;
unsigned long buffer3;
unsigned long buffer4;
sbit cs_adc_v2 at LATE4_bit;

void InitMain() {
CHECON = 0x32;
AD1PCFG = 0xFFFF;
SPI2_Init_Advanced(_SPI_MASTER, _SPI_32_BIT, 64, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_IDLE_2_ACTIVE);
TRISE4_bit = 0;
cs_adc_v2 = 1;

UART1_Init(57600);
// init SPI Hardware
UART1_Write_Text("LTC2400 ADC Test");

}
float volt;
float v_ref=3.0; // Reference Voltage, 5.0 Volt for LT1021 or 3.0 for LP2950-3

long int ltw = 0; // ADC Data ling int
int cnt; // counter
char t0; //
char sig; // sign bit flag
char st1[20]; // float voltage text

/********************************************************************/
void Main() {
InitMain();

cs_adc_v2 = 0; // LTC2400 CS Low
Delay_ms(1);
if (!(PINB & (1 << PB4))) { // ADC Converter ready ?
// cli();
ltw=0;
sig=0;

t0 = SPI2_read(buffer1); // read 4 bytes adc raw data with SPI
if ((t0 & 0x20) ==0) sig=1; // is input negative ?
t0 &=0x1F; // discard bit 25..31
ltw |= t0;
ltw <<= 8;
t0 = SPI2_read(buffer2);
ltw |= t0;
ltw <<= 8;
t0 = SPI2_read(buffer3);
ltw |= t0;
ltw <<= 8;
t0 = SPI2_read(buffer4);
ltw |= t0;

Delay_us(1);

cs_adc_v2 = 0; // LTC2400 CS Low
Delay_ms(200);

if (sig) ltw |= 0xf0000000; // if input negative insert sign bit
ltw=ltw/16; // scale result down , last 4 bits have no information
volt = ltw * v_ref / 16777216; // max scale

UART1_Write(cnt++);
UART1_Write("; ");
sprintf(volt,6); // print voltage as floating number
UART1_Write(" ");

}
cs_adc_v2 =1; // LTC2400 CS hi
Delay_ms(20);

}
/********************************************************************/
byte SPI2_read()
{
SPDR = 0;
while (!(SPSR & (1 << SPIF))) ; /* Wait for SPI shift out done */
return SPDR;
}
/********************************************************************/
// printFloat from tim / Arduino: Playground
// printFloat prints out the float 'value' rounded to 'places' places
//after the decimal point
void printFloat(float value, int places) {
// this is used to cast digits
int digit;
float tens = 0.1;
int tenscount = 0;
int i;
float tempfloat = value;

// if value is negative, set tempfloat to the abs value

// make sure we round properly. this could use pow from
//<math.h>, but doesn't seem worth the import
// if this rounding step isn't here, the value 54.321 prints as

// calculate rounding term d: 0.5/pow(10,places)
float d = 0.5;
if (value < 0)
d *= -1.0;
// divide by ten for each decimal place
for (i = 0; i < places; i++)
d/= 10.0;
// this small addition, combined with truncation will round our

tempfloat += d;

if (value < 0)
tempfloat *= -1.0;
while ((tens * 10.0) <= tempfloat) {
tens *= 10.0;
tenscount += 1;
}

// write out the negative if needed
if (value < 0)
UART1_Write('-');

if (tenscount == 0)
UART1_Write(0);

for (i=0; i< tenscount; i++) {
digit = (int) (tempfloat/tens);
UART1_Write(digit);
tempfloat = tempfloat - ((float)digit * tens);
tens /= 10.0;
}

// if no places after decimal, stop now and return
if (places <= 0)
return;

// otherwise, write the point and continue on
UART1_Write(',');

for (i = 0; i < places; i++) {
tempfloat *= 10.0;
digit = (int) tempfloat;
UART1_Write(digit);
// once written, subtract off that digit
tempfloat = tempfloat - (float) digit;
}
}
 

spinnaker

Joined Oct 29, 2009
7,830
It would help if you posted the lines causing each error. Don't expect people to count lines which may not even be accurate.
 

Thread Starter

house91320

Joined Feb 8, 2012
5
sprintf(volt,6); - 73 307 Illegal typecast 'can not convert to pointer' '' MyProject.c
byte SPI2_read() - 83 402 ; expected, but 'SPI2_read' found MyProject.c
byte SPI2_read() - 83 393 'SPI2_read' Identifier redefined MyProject.c
 

spinnaker

Joined Oct 29, 2009
7,830
Is "byte" a defined type in MikroC?

If not that is part of your problem.

At the top of your code you can try

#define byte unsigned char
 

Thread Starter

house91320

Joined Feb 8, 2012
5
Ok that got ride of one message, but its still saying
byte SPI2_read() - 84 393 'SPI2_read' Identifier redefined MyProject.c
sprintf(volt,6); - 74 307 Illegal typecast 'can not convert to pointer' '' MyProject.c
 

spinnaker

Joined Oct 29, 2009
7,830
Check your header file for byte SPI2_read().

I'll bet it is something like BYTE SPI2_read()

In which case match the line in your C file to what you see in the header.


Look at your documentation for sprintf. That call is totally wrong. For starters you need to supply a character array to print to.

Remember C is case sensitive.


Before you go any further I suggest you pick up a good book on C. This is really basic stuff.
 

PaulEE

Joined Dec 23, 2011
474
Ok that got ride of one message, but its still saying
byte SPI2_read() - 84 393 'SPI2_read' Identifier redefined MyProject.c
sprintf(volt,6); - 74 307 Illegal typecast 'can not convert to pointer' '' MyProject.c
MikroC is great in that you can double-click each function from the library manager list (if you can't see library manager window, go to view-->library manager).

Here, you can choose which libraries you want to include and double-click for the help documentation on each function.

unsigned char = 0-255 byte

Definitely have a look at the library manager stuff. Their help section is second to none. I happen to use MikroC A LOT, so I can help you with specific MikroC stuff if you need

Some other words:
SPI2_Read() needs a buffer character in it to generate the clock to read in the data. Example:

(top of your C code)
char dummy, data;

(where you call SPI2_Read())
data = SPI2_Read(dummy) // Reads a byte from SPI port

If you simply write "SPI2_Read()", MikroC thinks you're trying to re-define the function instead of thinking that you're calling it.

Strings in MikroC are char[] type. This is an array of characters. When you see implicit conversion of "int" to "pointer", you're not using the correct data type to display/read/convert strings into. Often, it assumes you're using "int" as the "pointer" (the number that refers to the specific location in your char[] array) since you type it like that.

again:

unsigned char[] myData = ""; // declaration of null string, MikroC might not let you do this
unsigned char[10] myData = (your string); // it usually likes predefined array sizes/values

Hope that helped.
 
Last edited:
Top