Author Topic: I2C Atmel  (Read 15998 times)

0 Members and 1 Guest are viewing this topic.

Offline d-jokic

  • Contributor
  • Posts: 25
  • Country: us
Re: I2C Atmel
« Reply #75 on: October 06, 2017, 05:33:48 pm »
 @funkathustra you're bang on; I don't know what I'm doing. I've never done embedded code from scratch, and frankly doubt I ever will; my degree isn't in that. So I've never learned it, and only worked with Arduino and TI (for a bit) before, which gives no exposure to actual embedded code. I'd love to go through and code the whole thing on my own, but I simply don't have the time and this needs to be finished asap, since there are other components to it.

My issue with Atmel Start is that is sets it all up, but it doesn't really say what's going on. So when I try and change the example to preform for example a reading over i2c rather than a write, I couldn't get it to work properly. That's why I prefer sample code (some thing that TI for example, has lots of) and usually rely on it to learn what going on in the code. Which is why I'm grateful people like @ataradov share their code; it's a great place to start. And it usually takes me a bit to figure out what's happening before I can properly use it.

@ataradov I knew it was one of those; this is what happens when you try and code late in the day. Thanks

 

Offline d-jokic

  • Contributor
  • Posts: 25
  • Country: us
Re: I2C Atmel
« Reply #76 on: October 06, 2017, 06:26:20 pm »
@ataradov, when you say
Quote
Your TXPO is also incorrect, it should be 1.
do you mean within

Code: [Select]
 
  SERCOM5->USART.CTRLA.reg =
      SERCOM_USART_CTRLA_DORD | SERCOM_USART_CTRLA_MODE_USART_INT_CLK |
      SERCOM_USART_CTRLA_RXPO(3/*PAD3*/) | SERCOM_USART_CTRLA_TXPO(2/*PAD2*/);


In the datasheet, it says that TX is on pin pb22 which is sercom5, pad 2. The only other occurrence of "txpo" is in the sercom.h file, and I didn't think that was what needs to be changed.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11257
  • Country: us
    • Personal site
Re: I2C Atmel
« Reply #77 on: October 06, 2017, 06:27:55 pm »
RXPO and TXPO do not represent PAD values directly, they are looked up in the table. Read the description of the RXPRO and TXPO fields, and you will see how they translate to pad values.
Alex
 

Offline d-jokic

  • Contributor
  • Posts: 25
  • Country: us
Re: I2C Atmel
« Reply #78 on: October 06, 2017, 09:06:06 pm »
Even with the changes you suggested, I still haven't gotten it to work. I have a functioning UART set up through Atmel Start, so I might try and merge that project with the one based off your code. If this a terrible idea? I couldn't find much about it online, a few people ask about doing it with Visual Studio, but I couldn't find anything about Atmel Studio. I know it'll affect things like the MakeFile.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11257
  • Country: us
    • Personal site
Re: I2C Atmel
« Reply #79 on: October 06, 2017, 09:08:52 pm »
If this a terrible idea?
It is a bad idea to jump from one thing to another. The original code is known to work, debug why it is not working. If you are going to drop everything that does not work from the first attempt, you will never get anywhere.

Post your latest version of the file with the changes for the arduino zero.
Alex
 

Offline d-jokic

  • Contributor
  • Posts: 25
  • Country: us
Re: I2C Atmel
« Reply #80 on: October 09, 2017, 11:50:25 pm »
I've managed to get UART working; I'm honestly not sure how, considering I made minimal changes to your code.

I'm still not able to use your i2c code to get data. One thing I tried doing is writing and reading to a register, and then displaying it on the monitor. I did:
Code: [Select]

//read value
uint8_t test1;
i2c_start(SLAVE_ADDRESS_WRITE); //master writes
i2c_write_byte(MAX30105_FIFOWRITEPTR); //address of write pointer
i2c_start(SLAVE_ADDRESS_READ); //master reads
i2c_read_byte(test1, true);
itoa(&test1, test, 20);
uart_puts(test);
i2c_stop();

//write value
i2c_start(SLAVE_ADDRESS_WRITE);
i2c_write_byte(MAX30105_FIFOWRITEPTR);
i2c_write_byte(0);
itoa(&MAX30105_FIFOWRITEPTR, test, 20);
uart_puts(test);

I get garbage readings for both; 87fcj1j for the first and 87f8h5i for the second. I'm sorry to be bugging you again, but I was wondering if you spot anything that seems off?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11257
  • Country: us
    • Personal site
Re: I2C Atmel
« Reply #81 on: October 09, 2017, 11:51:54 pm »
Well, you are still not cheeking the return values of the functions. They only return valid data if return value of the function is "true".
Alex
 

Offline d-jokic

  • Contributor
  • Posts: 25
  • Country: us
Re: I2C Atmel
« Reply #82 on: October 10, 2017, 12:17:24 am »
Good point. I've gone through and found that i2c_stop() returns false. Looking at the code, there is an if statement and a return true. Entering the if statement or not entering will return true, so I'm not sure what causes it to return false, apart from if not entering the function at all. But the program doesn't get stuck there, so that isn't the case.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11257
  • Country: us
    • Personal site
Re: I2C Atmel
« Reply #83 on: October 10, 2017, 01:43:33 am »
You need to publish the changes you make to the code. i2c_stop() can never return false. So you are obviously doing something wrong.
Alex
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf