I2C With Attiny402

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

Facing problem using I2C in attiny402. No proper documentation for start and stop condition.

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

What kind of documentation on the start and stop conditions are you missing? I just had a look at the datasheet and it seems to be all in there, but maybe I'm missing something?

- Brian

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

For start condition there are no such bits which corresponds for a start condition.

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

When I read the description of register MADDR it looks like it will automatically issue a start condition and transmit the address?

 

25.5.8 Master DATA

 

Name: MADDR
Offset: 0x07
Reset: 0x00
Property: -

 

Bits 7:0 – ADDR[7:0] Address
When this bit field is written, a Start condition and slave address protocol sequence is initiated dependent
on the bus state.

- Brian

Last Edited: Mon. Dec 17, 2018 - 10:01 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

True but when i check the current bus state after the address section through debugging mode then it still shows idle state.

But according to the literature it should be in busy state, right?

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

Have you verified that the address is sent and does the slave acknowledge?

 

What device is your slave?

- Brian

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

I'll bet the OP is using I2C functions with void return values!

The nice thing about I2C protocol is it will tell you what is wrong, but one must look at TWI status and ACT on it!

 

Jim

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

Lets go Brandon!

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

Hi,

 

Small honest advice, I was using Attiny212 and ATtiny402 + attiny412, The whole documentation is copy/paste from the bigger size version of the attiny 1 series. in conclusion: you can throw it in the garbage. full of mistakes, header file is also wrong with ports which doesnt exist, pin mux table is missing, configuration for the mux is missing, all in all "garbage".

 

chk this thread for your reference:

https://www.avrfreaks.net/forum/...

 

Regards,

Moe

 

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

And not mention another fact:

 

I was able to have some workarounds by myself by digging into these datasheets for attiny212/412 and attiny202/402, I reported the bugs to Atmel support at beginning of September, they promised to send me the corrected versions of both header files and datasheet and now its christmas, maybe I will get it as a newyear gift who knows ?. 

 

I will tell you how it will go:

- You ask them something, you get reply in 2-3 weeks,

- you answer for more clarifications, they come up with a missing answers or wrong answers in one week or at best 4 days, why ? because the people who are there they obviously are not engineers or I dunno, engineers but with a very low level of experience. they forward your questions to their superiors somewhere on x location on Earth.

- you get another another short missing answer....and so on.

 

waste of time, waste of energy...totally disrespectful to customers, I even sent an employee of atmel a message here on this board. "no answer at all".  They ignore you even if you said its urgent. At the end you have to figure it out yourself. in my experience they are quite nice people here in this forum who are very helpful, they will try to help you around but I repeat you have to figure a lot of things by yourself....

 

at the end, the datasheet version of Attiny202 is:

Revision A (3/2018):

Initial release.

 

for tiny212/412:

Rev. A - 01/2017

Initial release.

 

"01/2017" two years and its still the initial version, this is how they dont care about you, nor that they dont care about customers.

 

This is a short experience of a new user of Atmel/Microchip products, I used ST, Nordic...and some other MCU families but never experienced such a lack of seriousness like this. People would ask sometime why would somebody use, well avr is in general is also nice to work with but correct documentation remains one of the most obstacle that hinder the users/customers from using this stuff.

 

Regards,

Moe

 

 

 

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

I do not have a Tiny402.   I do have Tiny817, Mega4809, Xmega128A4.    I can assure you that the TWI peripheral is VERY similar.

 

Please ZIP up your AS7 project and attach the ZIP to your message.  

 

We can build your project and run it (on different AVR).

This should help you.

 

And if you or we discover errors in documentation there are several "voices" with test software to demonstrate the problem.

 

This will encourage attention from Microchip support team.    No one gets anywhere by being discourteous.

 

David.  

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

david.prentice wrote:

I do not have a Tiny402.   I do have Tiny817, Mega4809, Xmega128A4.    I can assure you that the TWI peripheral is VERY similar.

 

Please ZIP up your AS7 project and attach the ZIP to your message.  

 

We can build your project and run it (on different AVR).

This should help you.

 

And if you or we discover errors in documentation there are several "voices" with test software to demonstrate the problem.

 

This will encourage attention from Microchip support team.    No one gets anywhere by being discourteous.

 

David.  

 

David,

 

Almost everyone here knows how bad is the documentation of AVR's, I myself noticed it after very few time, at that time I thought it might probably exist only in Attiny212/412 which is 99% the same documentation like tiny402.

 

So we have to admit it here so somebody can hear our voice, if we keep denying it or close an eye this will not solve the issue. A datasheet which misses the simple pin/muxing description, missing information how to configure the muxing, copy/paste beyond belief is not something that somebody denies. You were kind ofcurse to offer your help as alway, but think about it, how many people our there in the industry are struggling to find right information in atmel's datasheets.

 

This problem has to be fixed, it should be fixed.

 

Regards,

Moe

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

Hey friend can you suggest me 8 pin 8 bit AVR attiny controller which has good documentation and sample codes for timer, I2C and ADC.

Thanks Jeet 

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

I would agree that datasheets are not always perfect. It is wise to report a problem.
.
If I was Microchip I would take comments from a multi-million unit customer very seriously. Even if the purchasing manager is an idiot.
I would not want to waste time with comments from students and hobbyists. Let's face it. 99.99% of problems are the user. 0.01% are hardware.
If a bug is well described and presented to Microchip support, it is more likely that they will accept it. A Forum like this can provide several members collaboration to verify the bug.
.
Some things are easy to resolve e.g. typos in documents.
Others might require Silicon revision or just be impossible.
.
Microchip have probably got a better reputation than Atmel but it looks as if a lot of Atmel structure has been retained.
.
David.

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

Jeet_1997 wrote:

Hey friend can you suggest me 8 pin 8 bit AVR attiny controller which has good documentation and sample codes for timer, I2C and ADC.

Thanks Jeet 

 

Hi,

 

I used tiny402 + and tiny 412 + tiny 212, if you look at the datasheet they all have the same pin numbers+the same garbage datasheet. I would suggest you to move up to 14 pin ATtiny214(if possible), this one looks that it has better datasheet. However you have to ask around in this forum, or perhaps David can help you, he is here for much more time in avrfreaks and he is quite active.

 

Regards

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

david.prentice wrote:
I would agree that datasheets are not always perfect. It is wise to report a problem. . If I was Microchip I would take comments from a multi-million unit customer very seriously. Even if the purchasing manager is an idiot. I would not want to waste time with comments from students and hobbyists. Let's face it. 99.99% of problems are the user. 0.01% are hardware. If a bug is well described and presented to Microchip support, it is more likely that they will accept it. A Forum like this can provide several members collaboration to verify the bug. . Some things are easy to resolve e.g. typos in documents. Others might require Silicon revision or just be impossible. . Microchip have probably got a better reputation than Atmel but it looks as if a lot of Atmel structure has been retained. . David.

 

I agree with a lot of what you said. However, I reported 3 months ago that the pin table in ATTINY212/ATTINY412 is wrong....three months ago, and the same wrong datasheet is still hanging up there. I sent message to Morten to inform him, nothing happen.

 

 

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

david.prentice wrote:
Let's face it. 99.99% of problems are the user. 0.01% are hardware.

 

Well, I have to make a scientific research to come up with this result ?!

 

:)

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

Jeet_1997 wrote:

Hey friend can you suggest me 8 pin 8 bit AVR attiny controller which has good documentation and sample codes for timer, I2C and ADC.

Thanks Jeet 

 

look at start.atmel.com / I see that they have tiny817 sample codes

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

Hey David as i am trying to debug the issues i can see that my clock peripheral frequency is always divided by 6 even if i try to change the register bits still it is not changing.

I am attaching the screenshot of the registers.

 

Code for system clock and fuses:

FUSES = {
    .WDTCFG = 0x00,
    .BODCFG = 0x00,
    .OSCCFG = 0x8E,
    .TCD0CFG = 0x00,
    .SYSCFG0 = 0xF6,    
    .SYSCFG1 = 0xFF, 
};
 

 

    CLKCTRL.MCLKLOCK &= ~(1);
    CLKCTRL.MCLKCTRLA &= ~(11);
    CLKCTRL.MCLKCTRLB &= ~(1);
    CLKCTRL.MCLKLOCK |= 1;
    
    CLKCTRL.OSC20MCTRLA |= 1<<1;
   // CLKCTRL.OSC20MCALIBA &= ~(1);
    CLKCTRL.OSC20MCALIBB |= 1<<7;

 

Thanks 

Jeet

Attachment(s): 

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

Hey Friend i am using MPLAB as an ide to program attiny402 so are there any such samples codes for MPLAB IDE.

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

this is because you are setting the prescaler to 6. disable the prescaler by writing 0 to the precaler bit.

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

Jeet_1997 wrote:
MPLAB as an ide to program attiny4

 

I have no idea. but normally attiny 1 and 0 seies are supported in atmel studio, so switching to atmel studio would save u a time.

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

Moe123 wrote:

this is because you are setting the prescaler to 6. disable the prescaler by writing 0 to the precaler bit.

 

dont forget to do the CCP, check the thread i told you before to check it and refer to what "clawson" said about CCP

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

Done but still the results are same.

 

Code for system clock and fuses:

FUSES = {
    .WDTCFG = 0x00,
    .BODCFG = 0x00,
    .OSCCFG = 0x8E,
    .TCD0CFG = 0x00,
    .SYSCFG0 = 0xF6,    
    .SYSCFG1 = 0xFF, 
};
 

 

    CLKCTRL.MCLKLOCK &= ~(1);
    CLKCTRL.MCLKCTRLA &= ~(11);
    CLKCTRL.MCLKCTRLB &= ~(1);
    CLKCTRL.MCLKLOCK |= 1;
    
    CLKCTRL.OSC20MCTRLA |= 1<<1;
   // CLKCTRL.OSC20MCALIBA &= ~(1);
    CLKCTRL.OSC20MCALIBB |= 1<<7;

Attachment(s): 

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

Hey there is no such mentioning about CCP can you be little more specific on areas where i need to check.

Thanks 

Jeet

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

have you checked the start.atmel.com, there is plenty of examples for attiny817 xplained pro. open one of them and then check the example code you will see the clkctrl.c.

 

to change the CLK setting you have to write to the CCP before your settings are applied. check for CCP in the datasheet also

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

Hey i tried configuring CCP register bits but while reading it the it should NULL and still other main clock bits are same so i guess the CCP didnt worked out. And it is important to configure CCP bits to change main clock register bits. SO my question is how to configure CCP bits and other main clock register bits?

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

you havent looked at my last post here regarding start.atmel.com.....

Last Edited: Tue. Dec 18, 2018 - 12:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Example of writing a protected register:

 

/*
	Set 10x divider for main clock. This results in a 2 MHz clock.
*/
void clock_init(void){
	_PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_10X_gc | CLKCTRL_PEN_bm);
}

 

This question is coming up very often, maybe a tutorial is needed...

 

edit: the _PROTECTED_WRITE macro can be found in the <avr/xmega.h> header file, but normally you don't need to include it explicitly.

Last Edited: Tue. Dec 18, 2018 - 01:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

El Tangas wrote:

Example of writing a protected register:

 

/*
	Set 10x divider for main clock. This results in a 2 MHz clock.
*/
void clock_init(void){
	_PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_10X_gc | CLKCTRL_PEN_bm);
}

 

This question is coming up very often, maybe a tutorial is needed...

 

Yeah I think so also, I refered him to start.atmel, which have plenty of examples to make the CLK configuration.

 

A tutorial is indeed a good idea, actually I learnt about this CCP some months ago from clawson

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

If you post a buildable project readers might help you to debug it.
.
I am too lazy to try and reconstruct from your posts. It ends up as a lot of wasted time.
Provide your real code and we know exactly what your program is doing. And we can compare with error-prone datasheets.
.
David.

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

Jeet_1997 wrote:
Hey friend can you suggest me 8 pin 8 bit AVR attiny controller which has good documentation and sample codes for timer, I2C and ADC.

ATtiny25/45/85

 

See app notes for I2C using the USI.

 

Jim

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

Lets go Brandon!

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

Please find my project below.

My queries is regarding the main clock.

System clock frequency is by default divided by 6 i want to prescale it to 1.

I have tried using CCP also but the results are same.

In the code i have just toggle the GPIO to check the system frequency.

 

Thanks

Jeet

Attachment(s): 

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

Can you recommend a good tutorial for CCP registers?

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

It is a xmega header file can we use it for ATTiny controllers.

I tried using atiny402 header file but still there was a error.

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

Jeet_1997 wrote:

Can you recommend a good tutorial for CCP registers?

 

Why you dont listen, Why havent you checked the examples for tiny817 on start.atmel.com ? Its self-explainable. !

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

Thanks for posting your project.    You appear to be using MPLABX with the xc8 compiler and Pickit4 debugger.

 

I can build your project on AS7 with the regular GCC compiler.   Unfortunately the AS7 Simulator crashes on the Tiny402.

I can build and simulate for the Tiny817.    (and run on Tiny817 hardware)

 

I can build on MPLABX and the MPLABX Simulator does not crash.

 

I strongly advise you to use the proper header file macros e.g.

void init(void)
{

    CCP = CCP_IOREG_gc;
    CLKCTRL.MCLKLOCK &= ~(CLKCTRL_LOCKEN_bm);        //(1);
    CCP = CCP_IOREG_gc;
    CLKCTRL.MCLKCTRLB &= ~(CLKCTRL_PEN_bm);          //(1);
    CCP = CCP_IOREG_gc;
    CLKCTRL.OSC20MCTRLA |= CLKCTRL_RUNSTDBY_bm;      //1<<1;
    CCP = CCP_IOREG_gc;
    CLKCTRL.OSC20MCALIBB |= CLKCTRL_LOCK_bm;         //1<<7

    TCA0.SINGLE.PER = 10486;                         //0x28F6;
    TCA0.SINGLE.CTRLA |= 4 << TCA_SINGLE_CLKSEL_gp;  //( 4 << 1);
    TCA0.SINGLE.CTRLA |= TCA_SINGLE_ENABLE_bm;       //1;
    TCA0.SINGLE.CTRLB = 0x00;
    TCA0.SINGLE.INTCTRL |= TCA_SINGLE_OVF_bm;        //1;

}

This is far easier to follow (for me).    The most important point is that CCP_IOREG is not 0x9D

 

I strongly advise you to invest in a $10 XMINI-tiny817 and a $10 Logic Analyser.     It will pay for itself by saving you brain-ache and TIME.

 

I am more familiar with AS7 than MPLABX.    I can certainly walk you through MPLABX or AS7 with the XMINI.    It is unfortunate that AS7 Simulator does not work for Tiny402.

 

People seem to think that an 8-pin chip is easier to learn on.    In my opinion it is easier to learn on a "well endowed" chip.   Preferably on a XMINI or XPRO evaluation board.

 

You can develop your project on the "big" chip.   When debugged,   you recompile for the smaller target chip.    It also means that you can do the final tests by comparing the target with the working "big chip" prototype.

 

David.

Last Edited: Wed. Dec 19, 2018 - 06:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey David i tried changing the init function but the result is same the registers under CCP are not changing.

Attaching the screenshot of the debug mode when i actually pause my system to see all the registers.

I tried compiling through AS7 but my project was not able to build.

I actually took help of Atmel start configured my clock control registers and then import it to AS7.

But it didnt build my code.

Attachment(s): 

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

Hey David i have doe few changes in the code and using atmel start and atmel studio i am able to configure the system clock.

But i am still facing issue with I2C the DATA line and CLOCK are constantly high.

Using Simulator in atmel studio 7, i think i might have ended up creating errors in I2C program.

Can you help me out please.

Details:

PA1 is SDA

PA2 is SCL

PA6 is just a GPIO toggling pin.

 Attaching AS7 project.

Attachment(s): 

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

Which country are you in?

Why have you chosen the Tiny402?

What experience do you have?

 

The AS7 Simulator crashes on Tiny402 and Tiny412.

The AS7 Simulator works ok on Tiny404, 406, 414, 416, 417.

 

"Atmel Start" is not easy to follow.   It makers my brain hurt.

 

Please explain what you want to do with an 8-pin chip.

I am happy to help you if you start using proper header macros instead of magic numbers (without comment).

 

I do not want to have to look up every magic number for you.    The occasional magic number is ok if you add an explanatory comment.

The header macros are self explanatory.    You just have to document something that is unusual.

 

David.

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

david.prentice wrote:

Which country are you in?

Why have you chosen the Tiny402?

What experience do you have?

 

The AS7 Simulator crashes on Tiny402 and Tiny412.

The AS7 Simulator works ok on Tiny404, 406, 414, 416, 417.

 

"Atmel Start" is not easy to follow.   It makers my brain hurt.

 

Please explain what you want to do with an 8-pin chip.

I am happy to help you if you start using proper header macros instead of magic numbers (without comment).

 

I do not want to have to look up every magic number for you.    The occasional magic number is ok if you add an explanatory comment.

The header macros are self explanatory.    You just have to document something that is unusual.

 

David.

 

Hi David,

 

The AS7 crashes because I think you are using the old atdf file ( 1.3.172 ), update to 1.3.229 and then it will be fine.

 

Check this thread https://www.avrfreaks.net/forum/...

 

if you dont want to update the atdf, you have to change the device signature manually. I've used the ATtiny402 + 202 & attiny412 and 212, the AS7 worked perfectly with them.

 

regards,

Moe

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

As for our friend the OP,I think he is trying to make a homework from school.

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

Hey friend,

I am just trying to find out the why I2C is not working in attiny402.

I have used USART which are in the same pins as of I2C and they are performing appropriately.

Using the same headers as of atmel start i have performed USART in attiny402.

If the headers are same and pin is same then i might be stuck somewhere in the protocol section of I2C in attiny402.

So my concern is the protocol section for I2C and its command which are handled in attiny402.

If you have valuable information for my query please do share.

As said by you i have used atmel start for configuring my headers.

Thanks for the help

 

Regards

Jeet

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

Hello David,

Thank you for your constant replies to this thread it means alot.

I am from India, and i have chosen attiny402 because i need to perform only single task of sending 12 bytes via I2C and this ICS seems sufficient.

The other ICS suggested seems over designed and with extra capability pins which are not required for my operation.

I do agree that Atmel start is not easy to follow because it includes too many headers and do not have proper comment sections.

But using atmel start my job for configuring clock is easily done and it doesnt affect my other peripherals as seen in USART code.

As i have explained above in this message my task is to send 12 bytes of data via I2C.

If possible can you be more specific in I2C protocol related problem because i think my major issue would be the manner in which I2C protocol is written.

 

Thank You

Jeet.

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

Thanks for the ATDF tip.   This makes the AS7 Simulator "work".    I am not sure how "well".

 

Experimenting with a new chip sounds like very HARD homework to me.

On the other hand,   schoolteachers and professors are sometimes vindictive.

 

Replacing magic numbers looks like this:

        for ( i = 0; i<10; i++)
        {  

            
            TWI0.MCTRLB |= TWI_MCMD_STOP_gc; 
            
            TWI0.MCTRLA = TWI_RIEN_bm | TWI_WIEN_bm | TWI_ENABLE_bm; //0xC1;

            TWI0.MADDR = 0xA4;
            while(!(TWI0.MSTATUS & TWI_WIF_bm)); 
            TWI0.MSTATUS |= TWI_WIF_bm;

            TWI0.MDATA = 0x50;
            while(!(TWI0.MSTATUS & TWI_WIF_bm)); 
            TWI0.MSTATUS |= TWI_WIF_bm;

            TWI0.MDATA = 0x56;
            while(!(TWI0.MSTATUS & TWI_WIF_bm)); 
            TWI0.MSTATUS |= TWI_WIF_bm;

            TWI0.MCTRLB |= TWI_MCMD_STOP_gc;
            while(!(TWI0.MSTATUS & TWI_RXACK_bm));
            TWI0.MCTRLB &= ~TWI_ACKACT_bm;
            
            PORTA.OUTTGL = 1 << 6;
        }

0xA4 sounds like a 24Cxx EEPROM with 7-bit address 0x52.

If it is a small one like 24C08 it would select location 0x50 and write data 0x56 to that page.   The EEPROM will not ACK during the page-write.

 

If it is a larger one like 24C256,  it would select location 0x5056.   No page write.

 

David.

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

you have to to write the PORTMUX, As you have seen in the table in page 14, for TWI:

 

PA1 -> SDA

PA2 ->SCL

 

which means that you have to select the alternative pin, thus, you have to right to the PORTMUX register in order to configure these pins as TWI, how to do this ? it seems theoritically possible, but practically its not written in the datasheet (refer to PORTMUX register), some information are missing.

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

david.prentice wrote:
Thanks for the ATDF tip. This makes the AS7 Simulator "work". I am not sure how "well"

 

welcome

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

Hello David,

I tried your replaced code but the results are same.

Results:

SDA and SCL are constant high 

So i guess the master is not enabled properly or the pins are not branched to SDA and SCL properly.

0xA4 is the address to one of my random slave and it can be any other number. 0x50, 0x56 is the data which i need to send to my slave and it also can be any value.

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

Correct, as there are commands for USART and SPI for choosing the alternative pins but for I2C these information is not given.

Are there any other alternative way or I2C can't be programmed in attiny402.

 

Thanks

Jeet

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

for this you have two ways to clarify it:

 

1- make a support tick at MC website and wait for their reply as they the information, this may take sometime, one day..two..a week, I dont know.

2- try to choose Attiny402 as target mcu in start.atmel.com, choose the TWI in your setting...and then trace how is the TWI is configured.

 

 

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

If you can explain what you want to do,  we can help you.

 

I do not know what a "random slave" is.    0x50 is commonly used for "memory" hardware devices.   But Slave address values are not cast in stone.

 

I have done nothing more than attempt to guess what you are trying to do.

If I knew,   I would run it on real hardware e.g. XMINI-tiny817.   e.g. show you how to use the TWI and report on USART (Serial Terminal)

 

Is this a school project?

Is your teacher a masochist?

 

What hardware do you have?   e.g. USART-USB dongle,   Logic Analyser, Oscilloscope, ...

 

Is there a reason for choosing the Tiny402?

 

David.

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

Exactly. This is completly nonsense what we are doing here, the guy started with the question of writing to the CLK and now its shifting to TWI.

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

My slave is an DRV10983 BLDC controller IC. I have previously implemented I2C using a DSPIC to drive this IC and it worked properly using address of slave (0xA4) and data bytes.

I have developed and implemented on hardware the complete solution to drive a 40WAtt BLDC motor (DSPIC + DRV combination). My motor is working perfectly fine.

 

Now, I just need to reduce the size from DSPIC to attiny as only I2C is needed to send command to DRV.

 

I have PICKIT4 and oscilloscope 

 

Since only single function(I2C) is needed from the microcontroller I chose ATTINY402.

 

Thanks 

Jeet

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

My basic question was for clock but as you reply suggested to use atmel start, that issue got resolved but as the thread is in respect to I2C and the problems in regards to I2C are still not resolved.

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

Jeet_1997 wrote:

My slave is an DRV10983 BLDC controller IC. I have previously implemented I2C using a DSPIC to drive this IC and it worked properly using address of slave (0xA4) and data bytes.

I have developed and implemented on hardware the complete solution to drive a 40WAtt BLDC motor (DSPIC + DRV combination). My motor is working perfectly fine.

 

Now, I just need to reduce the size from DSPIC to attiny as only I2C is needed to send command to DRV.

 

I have PICKIT4 and oscilloscope 

 

Since only single function(I2C) is needed from the microcontroller I chose ATTINY402.

 

Thanks 

Jeet

This would have been sensible information to put in your first message.

Choosing a new chip with inadequate documentation is unfortunate.

 

The DRV10983 has no register 0x50  (as far as I can see)

 

I conclude that you are just seeking to waste people's time.    I will give up.

 

David.

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

david.prentice wrote:

Jeet_1997 wrote:

My slave is an DRV10983 BLDC controller IC. I have previously implemented I2C using a DSPIC to drive this IC and it worked properly using address of slave (0xA4) and data bytes.

I have developed and implemented on hardware the complete solution to drive a 40WAtt BLDC motor (DSPIC + DRV combination). My motor is working perfectly fine.

 

Now, I just need to reduce the size from DSPIC to attiny as only I2C is needed to send command to DRV.

 

I have PICKIT4 and oscilloscope 

 

Since only single function(I2C) is needed from the microcontroller I chose ATTINY402.

 

Thanks 

Jeet

This would have been sensible information to put in your first message.

Choosing a new chip with inadequate documentation is unfortunate.

 

The DRV10983 has no register 0x50  (as far as I can see)

 

I conclude that you are just seeking to waste people's time.    I will give up.

 

David.

 

same here I'm also out.

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

I2C (TWI) signals are not BUSY and IDLE.  Maybe some UART signals were called that way back in the 20th century.  

 

I2C signals are 'asserted'  (SDA or SCL pulled to low) or 'released' (SDA/SCL allowed to be pulled to up Vcc by the 3K external pull-up resistors that are somewhere in the I2C circuit, hopefully).   Multiple sources can 'assert' the SDA line and only the Master can 'assert' the SCL line.  The SDA line is not in 'released' state until all the devices that are connected to SDA have 'released' this line.

 

If you are simply trying to do something easy like write 12 bytes over the I2C channel from the CPU to the external device, my advice is to simply use an Arduino Nano or ProMini.  The Nano costs about $4 USD on eBay and the ProMini costs about $2.50 USD.  It isn't the chip cost that is important: it is ALL the support libraries that are available and all the working demos that are available for Arduino. So you can get your application functioning is 1/10th the time that it takes using a "naked" AVR chip.  So your ATtiny402 costs $0.41 cents.  You still need an new and expensive programmer for its new (non-standard) UPDI interface.  And you have to spend MANY MANY hours reading the datasheets and experimenting to get it working right.

 

  Suppose you spend four hours on this simple I2C project.  If your time is worth $12-$15 an hour USD then you have spent $50-$60 on this application.  An Arduino Nano using the Wire.h library would have it up and running in 15 minutes.   $3 for 15 minutes developer salary plus $3.50 for an Arduino Nano module board: $6.50 total cost vs.  $60+ for a system that might work after four hours of research, coding, and troubleshooting.  Plus you still have to buy the new device programmer.    Unless you are an AVR expert, using Arduino is a no-brainer for small, limited-run projects. And the best way to become an AVR expert is to study the source code for the libraries that thousands of people have supplied for the Arduino to do things like USART, SPI, I2C, PWM, etc...

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

Simonetta wrote:

Multiple sources can 'assert' the SDA line and only the Master can 'assert' the SCL line.

 

While the master is the one pulling SCL low, any device

connected to the I2C bus can hold SCL low even after it

has been released by the master.  This allows a slow

device to regulate the bus speed in case the master is

going too fast for it.

 

--Mike

 

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

Jeet_1997 wrote:

SDA and SCL are constant high

Same problem I had with Mega4808.
Reason: Wrong value in TWISPIROUTEA (Portmux).

Last Edited: Sat. Apr 6, 2019 - 10:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

GermanFranz wrote:
Jeet_1997 wrote:

SDA and SCL are constant high

Same problem I had with Mega4808. Reason: Wrong value in TWISPIROUTEA (Portmux).

 

Herr Franz,

 

TWISPIROUTEA ?!!!.

 

Regards,

Moe