Skip to content

Can't instantiate attiny_hal::Adc for attiny85 application. #315

Answered by Rahix
tbezemer asked this question in Q&A
Discussion options

You must be logged in to vote
#[no_mangle]
pub extern "C" fn main() {

First of all, this doesn't look right. You should be using the attiny_hal::entry macro like this:

#[attiny_hal::entry]
fn main() -> ! {
    ...
}

That out of the way, the problem is that the ADC needs to know about your clock-rate. As the rate is not fixed, you have to make it explicit in your code. The best way to do this is to define the clock-rate globally and then reference that type everywhere else. Then you can easily change the clock-rate in the future. It works like this:

pub type CoreClock = attiny_hal::clock::MHz1;

#[attiny_hal::entry]
fn main() -> ! {
    let mut adc = attiny_hal::Adc<CoreClock>::new(...);
}

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Rahix
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #293 on September 02, 2022 10:40.