Atmel Start I2C not working for me

Go To Last Post
50 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

 

I'm new to AVR microcontrollers I used to work with PIC Anyway, I wanted to test the I2C bus on my custom Attiny1607 board with the Pickit4 to program it and  I wanted to read the temperature with MCP9600  https://www.microchip.com/wwwproducts/en/MCP9600  So I used Atmel Start to configure the project and used a logic analyzer to see the output It was very weird and didn't work at all.

#include <atmel_start.h>
#include <util/delay.h>
#define slave_adder 0x60
#define slave_register 0x00

int main(void)
{
	/* Initializes MCU, drivers and middle ware */
	atmel_start_init();
	I2C_0_open(slave_adder);
	
	
	uint16_t Temp;
	

	/* Replace with your application code */
	while (1) {
		_delay_ms(250);
		Temp = I2C_0_read2ByteRegister(slave_adder,slave_register);
		printf(Temp >> 4);		
	}
}

The value is always 02

Any thoughts?

 

 

Attachment(s): 

This topic has a solution.
Last Edited: Thu. Jan 16, 2020 - 12:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The usual "issue" when it comes to I2C is the device address. Because it forms 7 of 8 bits (with bit 0 being the R/W flag) there is often a question of whether it is specified as just plain 7 bits or the upper 7 of 8. So a device might be 0x23 but addressed as 0x46 (or vice versa). So I'd try replacing:

#define slave_adder 0x60

with either

#define slave_adder 0x30

or

#define slave_adder 0xC0

(ie double it or half it) and see if that helps.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Always check the return status of I2C functions, don’t assume they just work, the status will tell you what is wrong, but you have to look!

jim

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your post I just tried what you suggested and unfortunately I keep getting a NACK with both of them.

  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
the status will tell you what is wrong

Indeed. For example, if you don't get an ACK that is most likely due to an incorrect slave address - as clawson mentioned.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ebra wrote:
I keep getting a NACK

Probably means, as clawson suggested, that you have the Slave Address wrong.

 

More on that:

 

https://www.avrfreaks.net/commen...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
double it or half it) and see if that helps

Or just try sending all 127 addresses - and see which one gets an ACK!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

clawson wrote:
double it or half it) and see if that helps

Or just try sending all 127 addresses - and see which one gets an ACK!

The one I have in my code gives me an ACK If you look at the attachment you be able to see all the logic in scl and sda I numbered them.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In #4, you said you're getting NACK ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In #2 I was suggested to change the address double or half of it. When I tried to do it a got a NACK, I got an ACK with my code but it was for a write for some reason I wanted to read the register.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What exactly are you using to show the pretty picture in post #4?  Is it your scope?  Some kind of logic analyzer? 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From 1.png in #1 you have ACKed a 7-bit Slave Address = 0x60

 

If your library code expects 7-bit addressing,  use 0x60

If your library code expects 8-bit addressing,  use 0xC0 for Write and 0xC1 for Read.

 

Respected I2C library code will return status values from most of the functions.    Use the return values.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ebra wrote:

printf(Temp >> 4);	

How does that even compile (I'm assuming C code) ?

Is this some non standard printf ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I *think* printf() with one parameter may just be converted to a puts() but obviously the parameter it's being given is not the address of a string.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess it would do an implicit cast - but surprised if there's no warning ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What exactly are you using to show the pretty picture in post #4?  Is it your scope?  Some kind of logic analyzer? 

It's a Hobby Components USB 24M 8CH Logic Analyser with sigrok software.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

From 1.png in #1 you have ACKed a 7-bit Slave Address = 0x60

 

If your library code expects 7-bit addressing,  use 0x60

If your library code expects 8-bit addressing,  use 0xC0 for Write and 0xC1 for Read.

 

Respected I2C library code will return status values from most of the functions.    Use the return values.

 

David.

I tried 0xC0 and 0xC1 I only get an ACK from 0x60, I'm storing the return in Temp and displaying it on the UART bus it gives me a 02, I shouldn't do that? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MrKendo wrote:

Ebra wrote:

printf(Temp >> 4);	

How does that even compile (I'm assuming C code) ?

Is this some non standard printf ?

 

No this is some bit shifting for it to display the degrees in celsius.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

These are the warnings I get.

Last Edited: Thu. Jan 16, 2020 - 06:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


awneil wrote:
I guess it would do an implicit cast - but surprised if there's no warning ...

Yes - that is exactly what the first warning is telling you!

 

 

Note that it's a whole lot easier if you post the messages as text - then we don't have to mess about with cropping images!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1


I would forget concentrating on the printf() thing for now., far more serious would appear to be:

 

 

I'm assuming the project builds without error so the linker does manage to resolve this - but there's a serious problem if the .h that declares the function interface is not being found.

 

Try a Ctrl-Shift-F and search across the entire solution for that symbol name.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

for the printf, the point is, it should be something more like

printf("%u", Temp >> 4);

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
I would forget concentrating on the printf() thing for now

Well, it's a simple fix (eg, #22) - but, agreed, not the key issue with getting the I2C to work.

 

 

 the linker does manage to resolve this

Indeed.

 

But, with 'C',  the linker will just match on the name of the function - the implicit (ie, default) declaration might not have the expected parameters ...

 

So, yes - this one really does need to be fixed !

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are no errors, The warning sometimes show and sometimes they don't especially when I changed it form 

printf(temp >> 4);

To

 

puts(Temp);

It's really weird even when I just add a space they come back

Warning        passing argument 1 of 'puts' makes pointer from integer without a cast [-Wint-conversion]
Warning        implicit declaration of function 'I2C_0_read2ByteRegister' [-Wimplicit-function-declaration]

 

The exact same code sometimes it shows me the error and sometimes it doesn't.

 

awneil wrote:

awneil wrote:
I guess it would do an implicit cast - but surprised if there's no warning ...

Yes - that is exactly what the first warning is telling you!

 

 

Note that it's a whole lot easier if you post the messages as text - then we don't have to mess about with cropping images!

Want me to look for the I2C_0_read2ByteRegister function? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ebra wrote:
The warning sometimes show and sometimes they don't

That's because the warning will only be produced when the file containing them is compiled.

 

The whole point of the build system is that files are not compiled unless they specifically need it; ie, they have changed, or something they #include has changed.

 

It's really weird even when I just add a space they come back

See above - that's exactly to be expected!

 

 

Want me to look for the I2C_0_read2ByteRegister function? 

Yes - that is what you need to do!

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

More on "Implicit" declarations here:

 

https://www.avrfreaks.net/commen...

 

In particular, see the following posts:

 

https://www.avrfreaks.net/commen...

 

https://www.avrfreaks.net/commen...

 

which seem to suggest that, stupidly, START does not automatically add the required header for you!

 

(yes, that thread is about Xmega - but the principle is the same)

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MrKendo wrote:

for the printf, the point is, it should be something more like

printf("%u", Temp >> 4);

 

 

Thanks, the printf warning is gone the only warning is implicit declaration of function 'I2C_0_read2ByteRegister' [-Wimplicit-function-declaration]

 

awneil wrote:

Want me to look for the I2C_0_read2ByteRegister function? 

Yes - that is what you need to do!

 

 

 

This is in i2c_simple_master.c

uint16_t I2C_0_read2ByteRegister(i2c_address_t address, uint8_t reg)
{
	// result is little endian
	uint16_t result;

	while (!I2C_0_open(address))
		; // sit here until we get the bus..
	I2C_0_set_data_complete_callback(I2C_0_rd2RegCompleteHandler, &result);
	I2C_0_set_buffer(&reg, 1);
	I2C_0_set_address_nack_callback(i2c_cb_restart_write, NULL); // NACK polling?
	I2C_0_master_write();
	while (I2C_BUSY == I2C_0_close())
		; // sit here until finished.

	return (result << 8 | result >> 8);
}

This is in i2c_simple_master.h

uint16_t    I2C_0_read2ByteRegister(i2c_address_t address, uint8_t reg);

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you see #26 ?

 

I might have posted it at the same time you were posting #27

 

it looks like it does answer your question.

 

EDIT: I mean the issue of the implicit declaration - it may or may not be the cause of the problems with getting the I2C hardware actually working.

 

Ebra wrote:
This is in i2c_simple_master.c

So, as clawson said, you do have a definition for  I2C_0_read2ByteRegister  somewhere in your project - which is how your project manages to link OK

 

This is in i2c_simple_master.h

uint16_t    I2C_0_read2ByteRegister(i2c_address_t address, uint8_t reg);

But is that #included in the file which calls the function ?

 

 

EDIT

 

typos

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Jan 16, 2020 - 10:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry I think we posted almost at the same time, I tried doing this:

#include <atmel_start.h>
#include <util/delay.h>
#include "i2c_simple_master.h"

#define slave_adder 0x60
#define slave_register 0x00

int main(void)
{
	/* Initializes MCU, drivers and middle ware */
	atmel_start_init();
	
	
	
	uint16_t Temp;
	
	

	/* Replace with your application code */
	while (1) {
		_delay_ms(250);
		Temp = I2C_0_read2ByteRegister(slave_adder,slave_register);
		printf("%u", Temp >> 4);
	}
}

I don't get any warnings now! However, The Temp is always 0 maybe it's my IC? If it is would you advise me to try something else to test my I2C?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you confirmed that you are actually getting the correct activity on the physical I2C lines ?

 

EDIT

 

Your code doesn't do any initialisation or configuration of the sensor - is that correct ?

 

The usual first step is to read some register which has a known, fixed value; does this sensor have such a feature? eg, a device ID ... ?

 

 

EDIT 2

 

Ebra wrote:
would you advise me to try something else to test my I2C?

The obvious answer to that would be: Arduino !

 

EDIT 3

 

Or get a Microchip dev board for which there are ready-to-go, known-working examples in Atmel Studio (or MPLab)

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Jan 16, 2020 - 11:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Ebra wrote:

To

 

puts(Temp);

You need to learn some basic C. You cannot just puts() or printf() a numeric variable like this.

 

#28 shows that the return from the read2ByteRegister() is a uint16_t. You have to do a binary to ASCII conversion in some way to be able to print it. Simplest would be:

printf("%u", Temp);

but another approach is:

char text[10];
itoa(Temp, text, 10);
printf("%s", text);

but what you cannot do is simply:

puts(Temp);
or
printf(Temp);

 

Last Edited: Thu. Jan 16, 2020 - 11:02 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
You need to learn some basic C

Indeed - and the whole thing about implicit declarations, and "surprise" that Warnings don't always appear suggests that some more 'C' learning is needed.

 

Here are some 'C' learning & reference materials: 

 

http://blog.antronics.co.uk/2011...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You guys are right, I need more C I thought the C programming module in university was enough and it's clearly not, anyway the output is still the same I started with. 

I made a complete picture:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the OP you suggested you were familiar with PIC?

 

Most of this stuff is general - not specific to AVR.

 

Anyhow, your trace seems to show that the I2C is working:

  1. You send an address + write;
  2. You get an ACK to that address
  3. You send some data;
  4. You get an ACK to that data
     
  5. You send an address + read;
  6. You get an ACK to that address
  7. You get some data.

 

So now you need to go back to the sensor datasheet and make sure that you are using it correctly ...

 

EDIT

 

Corrected trace interpretation

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Jan 16, 2020 - 11:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Ebra wrote:
I thought the C programming module in university was enough and it's clearly not
Did it involve Arduino by any chance. Rather than printf() the output there tends to be using Serial.prinln(). Unlike printf() in plain old C, the println() method on the serial class is an overloaded C++ function so there are actually 10 or more different versions so you can do any of:

Serial.println(3);
Serial.println(3.14);
Serial.println("hello");
char x = 'A';
Serial.println(x);
long l = 0xBABEFACE;
Serial.println(l);

and the one "println()" appears to be able to accept all kinds of different parameters. It's as happy printing "hello" as 3.14.

 

This can lead newcomers to think that you can pass pretty much anything to a function like this and it will just handle it. But there's a lot of cleverness going on behind the scenes in the C++ world to make this happen. C and printf() aren't like this. That's why printf() has the form it does so you can do things like:

long l = 0xBABEFACE;
printf("%s %f %08X", "hello", 3.14, l)

with the %<format> entries in the first format string giving it a clue as to how it must handle the things that then follow.

 

Rather curiously C++ tried to "improve" the whole printf() thing by overloading the "<<" operator so you can in theory use:

long l = 0xBABAEFACE;
cout << "hello " << 3.14 << " " << l;

but most people (especially me!) think this is actually far worse than C's printf() !!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I meant I was a bit familiar with XC8 And MCC and have few PIC boards I didn't spend a lot of time learning microcontrollers I started learning them because one of my projects could use them. I got the same sensor because of a video microchip have on their youtube channel https://youtu.be/G_miVOX82os "How to implement I2C on PIC® and AVR® Microcontrollers " I will probably test something if it doesn't work now.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Did it involve Arduino by any chance.

It was only the old C which is surprising because I am an electrical and electronic engineering student, I did work with Arduino and made the whole project, I just want something a bit more professional like the XC compiler and AVR compiler. The reason I used printf was this :

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ebra wrote:
I just want something a bit more professional like the XC compiler and AVR compiler.

Atmel studio uses exactly the same GCC compiler as Arduino!

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I just want more options in terms of microcontrollers and not wait for Arduino to add support in my opinion, it is more efficient to use Atmel studio and Mplab X maybe I'm wrong.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ebra wrote:
I got the same sensor because of a video microchip have on their youtube channel https://youtu.be/G_miVOX82os

That video gives links for source code - have you tried that?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ebra wrote:
not wait for Arduino to add support

But Arduino already has well-proven known-working widely-used I2C code!

 

You can use that for the I2C comms, and talk directly to the sensor - no need to wait for anything else.

 

more efficient to use Atmel studio

But only if you are a proficient 'C' programmer and familiar with microcontrollers & I2C ...

 

Anyhow, as already mentioned, it does seem that your I2C is now working - so it's a question of how to use the sensor properly ...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Ebra wrote:
I got the same sensor because of a video microchip have on their youtube channel https://youtu.be/G_miVOX82os

That video gives links for source code - have you tried that?

 

 

I tried the exact same board and the sensor with the source code and it didn't work. That was the reason I stopped learning PICs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, Thanks the I2C seems to be working as you said I think this is solved then right? I will experiment with other sensors that are easier to use.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is code for both AVR and PIC.

 

So have you looked at the AVR code?

 

Ebra wrote:
That was the reason I stopped learning PICs

That means you need to keep on learning - not give up!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ebra wrote:
I think this is solved then right?

 

In that case, see Tip #5 (in my signature, below; may not be visible on mobile)

 

Ebra wrote:
I will experiment with other sensors that are easier to use.

I suggest this: https://www.avrfreaks.net/commen...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It was using the XC8 compiler and it didn't work with my PIC I don't think it would work with AVR, but I will try.

awneil wrote:

 

That means you need to keep on learning - not give up!

 

Thanks, unfortunately, I think there is a lack of resources for people who are trying to learn or maybe it's just me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When learning any new skill, you need to start with the basics, lay good foundations, and build step-by-step.

 

When you try to leap into something too advanced, you are setting yourself up to fail.

 

I2C comms with advanced sensors is not a beginners project, I'm afraid - as you've seen, it does rely upon you being familiar with a number of underlying concepts ...

 

See Tip #6.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot for the help I will start with the basics now, I will come to this later.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you consider this thread resolved, please mark the solution - that's  Tip #5.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just did thanks.