Hi All,
I’m having trouble getting the MicroMag3 to work. At this point, I can’t get it to set the DRDY line high.
I have the SS line grounded. I pulse the RESET line high, then send the command byte (0x01, for an x-axis reading), but the MicroMag3 doesn’t set the DRDY line high to indicate that it’s performed a reading.
If anyone can see what I’m doing wrong I’d greatly appreciate a correction. Thanks!
I’m using an Atmega324p. Here’s a code snippet:
void SPI_MasterInit(void)
{
DDR_SPI |= (1<<DD_MOSI) | (1<<DD_SCK);
SPCR0 |= (1<<SPE0) | (1<<MSTR0) | (1<<SPR01);
}
uint8_t spi_transfer(uint8_t data)
{
SPDR0 = data; // start the transmission
PD5Value = PIND & _BV(PD5); // read the DRDY pin
while (PD5Value == 0) // wait till data is ready
{
PD5Value = PIND & _BV(PD5); // read the DRDY pin
printf(" . ");
}
return SPDR0; // return the received byte
}
uint8_t MM3;
int counter;
int main(void)
{
init_usart(); // Initialize usart
stdout = &mystdout; // set the output stream
SPI_MasterInit(); // Initialize micromag3
DDRD |= (1<<6); // set RESET output
DDRD &= ~(1<<5); // set DRDY input
PORTD &= ~(1<<5); // DRDY pullup disabled
PORTD &= ~(1<<6); // RESET low
printf(" starting ");
// reset micromag3
PORTD |= (1<<6); // RESET high
counter=0;
while (counter<=20) // count to 20 while reset is high
counter++;
PORTD &= ~(1<<6); // RESET low
// send command byte
MM3 = spi_transfer(0x01);
printf(" sending command byte ");
// output result over rs232
printf(" result = %i ",MM3);
while (1)
{
}
}
[edit]corrected code[/edit]