Atmega32U4 + MAX1300 (ADC)

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everybody. I have a problem: atmega32u4 connected to max 1300 (https://datasheets.maximintegrat...) using SPI. MAX 1300 returns 0 value on ch7-ch1, exept ch 0. Please explain how to send commands to MAX1300 in a proper way. Because I dont really understand how to do it from MAX1300 datasheet. Also what SPI speed I should use? (I used 16 MHz crystall for Atmega32U4 and 1 MHz for SPI (fclk/16)).

for(i = 7; i >= 0; i--){

		 		 SPDR = 128 + i;                   //Get channel i data
		 		 SPDR = 0;                         //send 0 to initiate data interchange
		 		 while(!(SPSR & (1<<SPIF))){}
		 		 SPDR = 0;
		 		 while(!(SPSR & (1<<SPIF))){}
		 		 SPDR = 0;
		 		 result_h = SPDR;                  //read first byte from SPI data register
		 		 while(!(SPSR & (1<<SPIF))){}
		 		 result_l = SPDR;                  //read second byte from SPI data register

This is code for SPI module.