Linspire
Full Member level 5
Guys
I have done simple testing for RS-232 and SD card testing.
They are working properly now.
However when I combined both of them function, it doesn't display correct display and save wrong info input from RS-232.
Coding will posted as below:
Regards
Linspire
I have done simple testing for RS-232 and SD card testing.
They are working properly now.
However when I combined both of them function, it doesn't display correct display and save wrong info input from RS-232.
Coding will posted as below:
Code:
ADCON1 |= 0x0F; // Configure AN pins as digital
CMCON |= 7;
TRISB = 0; // Turn off comparators
PortB = 0xFF;
UART1_Init(9600);
Delay_ms(1000);
Lcd_Init();
// Initialize SPI1 module
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
while (Mmc_Init());
Lcd_Out(1,1,"SPI reintialized");
Delay_ms(1000);
Delay_ms(1000);
// use fat16 quick format instead of init routine if a formatting is needed
while(1) {
// use fat16 quick format instead of init routine if a formatting is needed
if (Mmc_Fat_Init() == 0) {
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"MMC init OK");
// reinitialize spi at higher speed
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
if (UART1_Data_Ready()){ //<------ Check if a character has been received before reading
uart_rd = UART1_Read(); // read the received data,
UART1_Write(uart_rd);
data2[number] = uart_rd;
number = number +1;
if (number == 12) // temp storing string
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_cmd(_LCD_RETURN_HOME);
Lcd_out(1,1,data2);
Mmc_Fat_Set_File_Date(2010, 4, 19, 9, 0, 0); // Set file date & time info
Mmc_Fat_Assign(&filename, 0xA0); // Find existing file or create a new one
Mmc_Fat_Rewrite;
Mmc_Fat_Write(data2,number);
Mmc_Fat_Write("\r\n",2);
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Test End");
break;
}
}
}else {
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"MMC init FAILED"); // Note: Mmc_Fat_Init tries to initialize a card more than once.
// If card is not present, initialization may last longer (depending on clock speed)
}
}
Regards
Linspire
Last edited: