Changeset - 7c7bd3044e69
[Not reviewed]
default
0 4 0
ethanzonca@CL-SEC241-08.cedarville.edu - 12 years ago 2012-11-09 17:00:43
ethanzonca@CL-SEC241-08.cedarville.edu
SD card datalogging working, master just writes hello world to sd card in a loop
4 files changed with 33 insertions and 33 deletions:
0 comments (0 inline, 0 general)
master/master/lib/logger.c
Show inline comments
 
@@ -30,13 +30,13 @@ void logger_setup()
 
		if(!sd_raw_init()) //sd_raw.c this function may need an overhaul
 
		{
 
			// initialization failed!!!!!!!
 
			PORTA |= 0b00000001;
 
			return;
 
		}
 
return;
 
 
		//check for SD exist/power/ready END
 
	
 
		/* open first partition */ 
 
		struct partition_struct* partition = partition_open(sd_raw_read,
 
															sd_raw_read_interval,
 
															sd_raw_write,
 
@@ -90,13 +90,15 @@ return;
 
			return;
 
		}
 
		//open directory END
 
		
 
		
 
		//simplified version of console BEGIN
 
		char buffer[24];
 
		char buffer[24] = "Omg this is cool, haha!";
 
		buffer[23] = 0xd;
 
		buffer[24] = 0xa;
 

	
 
		/* search file in current directory and open it */
 
		struct fat_file_struct* fd = open_file_in_dir(fs, dd, "data.csv"); //logger.h
 
		if(!fd)
 
		{
 
			PORTA |= 0b00000110;
 
@@ -109,23 +111,12 @@ return;
 
			//error seek to file handling
 
			PORTA |= 0b00000111;	
 
			fat_close_file(fd);
 
			return;
 
		}
 

	
 
		buffer[0] = 'H';
 
		buffer[1] = 'e';
 
		buffer[2] = 'l';
 
		buffer[3] = 'l';
 
		buffer[4] = 'o';
 
		buffer[5] = 'w';
 
		buffer[6] = 'o';
 
		buffer[7] = 'r';
 
		buffer[8] = 'l';
 
		buffer[9] = 'd';
 

	
 
		/* read text from the shell and write it to the file */
 
		uint8_t data_len = sizeof(buffer);
 
			
 
		while(1)
 
		{
 
			/* write text to file !! */
master/master/lib/sd/sd_raw.c
Show inline comments
 
@@ -181,28 +181,30 @@ uint8_t sd_raw_init()
 
    configure_pin_sck();
 
    configure_pin_ss();
 
    configure_pin_miso();
 

	
 
    unselect_card();
 

	
 
    /* initialize SPI with lowest frequency; max. 400kHz during identification mode of card */
 
    SPCR0 = (0 << SPIE0) | /* SPI Interrupt Enable */
 
           (1 << SPE0)  | /* SPI Enable */
 
           (0 << DORD0) | /* Data Order: MSB first */
 
           (1 << MSTR0) | /* Master mode */
 
           (0 << CPOL0) | /* Clock Polarity: SCK low when idle */
 
           (0 << CPHA0) | /* Clock Phase: sample on rising SCK edge */
 
           (1 << SPR10);   /* Clock Frequency: f_OSC / 128 */
 
    // initialize SPI with lowest frequency; max. 400kHz during identification mode of card
 
    SPCR0 = (0 << SPIE0) | // SPI Interrupt Enable 
 
            (1 << SPE0)  | // SPI Enable 
 
            (0 << DORD0) | // Data Order: MSB first 
 
            (1 << MSTR0) | // Master mode 
 
            (0 << CPOL0) | // Clock Polarity: SCK low when idle 
 
            (0 << CPHA0) | // Clock Phase: sample on rising SCK edge 
 
            (1 << SPR10);   // Clock Frequency: f_OSC / 128 
 
           //(1 << SPR00); // commentnig this out means /64, which gives over 100khz as required
 
    SPSR0 &= ~(1 << SPI2X0); /* No doubled clock frequency */
 
// transmit a char
 
 while ( ! ( SPSR0 & ( 1 << SPIF0 )));  //  wait for completion of
 
 SPDR0 = 'c';                            // begin transmission
 
    SPSR0 &= ~(1 << SPI2X0); // No doubled clock frequency 
 
 
 
/*
 
	while(1) {
 
		SPDR0 = 'a';					//Load byte to Data register
 
		while(!(SPSR0 & (1<<SPIF0))); 	// Wait for transmission complete
 
	}
 
*/
 

	
 
return;
 

	
 
    /* initialization procedure */
 
    sd_raw_card_type = 0;
 
    
 
    if(!sd_raw_available())
 
        return 0;
master/master/lib/sd/sd_raw_config.h
Show inline comments
 
@@ -70,13 +70,13 @@ extern "C"
 
/**
 
 * @}
 
 */
 

	
 
#define configure_pin_mosi() DDRB |= (1 << DDRB5) //PB5
 
#define configure_pin_sck() DDRB |= (1 << DDRB7) //PB7
 
#define configure_pin_ss() DDRB |= (1 << DDRB0) //PB0 - custom pin
 
#define configure_pin_ss() DDRB |= (1 << DDRB0) | (1 << DDRB4); PORTB |= (1<<DDRB4) //PB0 - custom pin, but pb4 must be set as output
 
#define configure_pin_miso() DDRB &= ~(1 << DDRB6) //PB6
 
	
 
#define select_card() PORTB &= ~(1 << PORTB0)
 
#define unselect_card() PORTB |= (1 << PORTB0)
 

	
 

	
master/master/master.c
Show inline comments
 
@@ -26,32 +26,39 @@
 

	
 
void micro_setup() {
 
	// Generic microcontroller config options
 

	
 
}
 

	
 

	
 
int main(void)
 
{
 
	// Initialize
 
	micro_setup();
 
	led_setup();
 
	//micro_setup();
 
	//led_setup();
 

	
 

	
 
	serial_setup(); // Config serial ports
 
	afsk_setup();
 
	//serial_setup(); // Config serial ports
 
	//afsk_setup();
 

	
 
	_delay_ms(400);	
 
	_delay_ms(400);	
 
	logger_setup(); // right now this blocks and writes text to the SD card
 
	
 
	logger_setup();
 

	
 
	
 
    while(1)
 
    {
 
		
 
		//afsk_test();
 
		//aprs_send();
 
		aprs_send();
 

	
 
		_delay_ms(400);
 
		_delay_ms(400);
 
		_delay_ms(400);
 
		_delay_ms(400);
 
		_delay_ms(400);
 
        //serial_SendCommand('0','A',0,0);
 
		
 
		
 
    }
 
}
 
\ No newline at end of file
0 comments (0 inline, 0 general)