Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

mikro c problem with spi data transfer

Status
Not open for further replies.

forsa

Newbie level 4
Joined
May 12, 2010
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,314
mikro c problem

hi,
im a student doing a project using mikro c. im new to this software and i learning it by my own. and now hopefully some of u all can enlighten me.

the problem i am facing now is the error of undeclared identifier for MASTER_OSC_DIV16, ATA_SAMPLE_MIDDLE ,CLK_IDLE_LOW, LOW_2_HIGH
when initialize the spi.

"Spi1_Init_Advanced(MASTER_OSC_DIV16,DATA_SAMPLE_MIDDLE,CLK_IDLE_LOW, LOW_2_HIGH);"

i have no idea what happen and i believe it is correct. pls ignore my bad language
 

so anyone can please help me out?
 

Hi forsa,

Can you tell us which microcontroller you used? You need a uC with hardware integrated SPI for using Spi function in the library.
 

its pic 18f452 microcontroller
 

Hi forsa,

I just tried it and found no errors. I believe you are using MikroC. If possible please post the complete code. I compiled the program using function 'Spi_Init...' instead of 'Spi1_Init...'.
 

well, using "spi_init" does not help too..
here are what i have written,

Code:
void main()
{
}
char filename[] = "TEMPERTRTXT";
unsigned short character;
unsigned long file_size,i,rec_size;
unsigned char ch1,ch2,flag,ret_status,choice;
unsigned char temperature[10],txt[12];
//
// This function sends carriage-return and line-feed to USART
//
void Newline()
{
Uart1_Write(0x0D); // Send carriage-return
Uart1_Write(0x0A); // Send line-feed
}
//
// This function sends a space character to USART
//
void Space()
{
Uart1_Write(0x20);
}
//
// This function sends a text to serial port
//
void Text_To_Uart1(unsigned char *m)
{
unsigned char i;
i=(0) ;
while(m[i] != 0)
{ // Send TEXT to serial port
Uart1_Write(m[i]);
i++;
}
}
//
// This function reads the temperature from analog input AN0
//
void Get_Temperature()
{
unsigned long Vin, Vdec,Vfrac;
unsigned char op[12];
unsigned char i,j;
Vin = Adc_Read(0); // Read from channel 0 (AN0)
Vin = 488*Vin; // Scale up the result
Vin = Vin /10; // Convert to temperature in C
Vdec = Vin / 100; // Decimal part
Vfrac = Vin % 100; // Fractional part
LongToStr(Vdec,op); // Convert Vdec to string in "op"
//
// Remove leading blanks
//
j=0;
for(i=0;i<=11;i++)
{
if(op[i] != ' ') // If a blank
{
temperature[j]=op[i];
j++;
}
}
temperature[j] = '.'; // Add ¡°.¡±
ch1 = Vfrac / 10; // fractional part
ch2 = Vfrac % 10;
j++;
temperature[j] = 48+ch1; // Add fractional part
j++;
temperature[j] = 48+ch2;
j++;
temperature[j] = 0x0D; // Add carriage-return
j++;
temperature[j] = 0x0A; // Add line-feed
j++;
temperature[j]='\0';
}
//
// Start of MAIN program
//
void main()
{
rec_size = 0;
//
// Configure A/D converter
//
TRISA = 0xFF;
ADCON1 = 0x80; // Use AN0, Vref = +5V
//
// Configure the serial port
//
Uart1_Init(2404);
//
// Initialise the SPI bus
//
Spi_Init_Advanced (MASTER_OSC_DIV16,DATA_SAMPLE_MIDDLE,CLK_IDLE_LOW, LOW_2_HIGH);
//
// Initialise the SD card bus
//
while(Mmc_Init(&PORTC,2));
//
// Initialise the FAT file system
//
while(Mmc_Fat_Init(&PORTC,2));
//
// Display the MENU and get user choice
//
Newline();
Text_To_Uart1("TEMPERATURE DATA LOGGER");
Newline();
Newline();
Text_To_Uart1("1. Send temperature data to the PC");
Newline();
Text_To_Uart1("2. Save temperature data in a new file");
Newline();
Text_To_Uart1("3. Append temperature data to an existing file");
Newline();
Newline();
Text_To_Uart1("Choice ? ");
//
// Read a character from the PC keyboard
//
flag = 0;
do {
if (Uart1_Data_Ready()) // If data received
{
choice = Uart1_Read(); // Read the received data
Uart1_Write(choice); // Echo received data
flag = 1;
}
} while (!flag);
Newline();
Newline();
//
// Now process user choice
//
switch(choice)
{
case '1':
ret_status = Mmc_Fat_Assign(&filename,1);
if(!ret_status)
{
Text_To_Uart1("File does not exist..No saved data...");
Newline();
Text_To_Uart1("Restart the program and save data to the file...");
Newline();
for(;;);
}
else
{
//
// Read the data and send to UART
//
Text_To_Uart1("Sending saved data to the PC...");
Newline();
Mmc_Fat_Reset(&file_size);
for(i=0; i<file_size; i++)
{
Mmc_Fat_Read(&character);
Uart1_Write(character);
}
Newline();
text_To_Uart1("End of data...");
Newline();
for(;;);
}
case '2':
//
// Start the A/D converter, get temperature readings every
// 10 seconds, and then save in a NEW file
//
Text_To_Uart1("Saving data in a NEW file...");
Newline();
Mmc_Fat_Assign(&filename,0x80); // Assign the file
Mmc_Fat_Rewrite(); // Clear
Mmc_Fat_Write("TEMPERATURE DATA - SAVED EVERY 10 SECONDS\r\n",43);
//
// Read the temperature from A/D converter, format and save
//
for(;;)
{
Mmc_Fat_Append();
Get_Temperature();
Mmc_Fat_Write(temperature,9);
rec_size++;
LongToStr(rec_size,txt);
Newline();
Text_To_Uart1("Saving record:");
Text_To_Uart1(txt);
Delay_ms(10000);
}
break;
case '3':
//
// Start the A/D converter, get temperature readings every
// 10 seconds, and then APPEND to the existing file
//
Text_To_Uart1("Appending data to the existing file...");
Newline();
ret_status = Mmc_Fat_Assign(&filename,1); // Assign the file
if(!ret_status)
{
Text_To_Uart1("File does not exist - can not append...");
Newline();
Text_To_Uart1("Restart the program and choose option 2...");
Newline();
for(;;);
}
else
{
//
// Read the temperature from A/D converter, format and save
//
for(;;)
{
Mmc_Fat_Append();
Get_Temperature();
Mmc_Fat_Write(temperature,9);
rec_size++;
LongToStr(rec_size,txt);
Newline();
Text_To_Uart1("Appending new record:");
Text_To_Uart1(txt);
Delay_ms(10000);
}
}
default:
Text_To_Uart1("Wrong choice...Restart the program and try again...");
Newline();
for(;;);
}
}
 

put the actual error messege ,i think u can solve the problem by using below two codes instead of your codes
Please reinitialize the spi device ,after while ((Mmc_Fat_Init(&PORTC, 2)!=0))
like
Spi_Init_Advanced(MASTER_OSC_DIV4, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);
 

Hi forsa,

Tell me the version of MikroC you are using. The name of the functions and constants are different in different versions.
 

I am using mikroc 8.2.0.0
but i think in any version name of the functions and constants are almost same.one think is that new version has new feature.
 

Hi ansarmytheen,

But not in MikroC. In MikroC PRO version, instead of 'MASTER_OSC_DIV16 ' you have '_SPI_MASTER_OSC_DIV16' .... and also instead of SPI1_init in MikroC PRO, you have SPI_Init in MikroC 8.1.':D'
 

hai sir,
i know that, but in above program the fellow using spi ini(...................) code.
thanks
 

well, i had solve the problem.. it about the library syntax. i noticed it is different between mikro c and mikro c pro.

however, i had another problem now, which is i could not get any pic18f452 anywhere nearby. any idea which replacement i should use?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top