Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Clock Frequency for USART Peripheral Running in SPI Mode #35

Open
martinmortsell opened this issue Oct 5, 2022 · 1 comment
Open
Labels
bug Something isn't working

Comments

@martinmortsell
Copy link
Contributor

martinmortsell commented Oct 5, 2022

I'm using the Usart peripheral in SPI Mode and it seems like the SCK is running at exactly 8 times the frequency I set it to.
E.g.

let spi_host_handle = handles.spi_host.configure(
    &usart_spi,
    &hclk,
    SpiConfig {
        bitrate: (2_000_000).bps(),
        mode: MODE_1,
    },).unwrap();                                 

yields a bitrate of 8MHz. I haven't explored this behaviour fully, but it seems to me that the cause is:

        const MIN_OVERSAMPLE: u32 = 8;
        let oversample_factor = MIN_OVERSAMPLE * if oversample { 2 } else { 1 };

in /usart/mod.rs
Compare 46.6.1.1 which is the current behaviour to 46.6.1.3 which is the desired behaviour in SPI Mode.

@martinmortsell martinmortsell changed the title Wrong Clock Frequency for USART Perihperal Running in SPI Mode Wrong Clock Frequency for USART Peripheral Running in SPI Mode Oct 5, 2022
@martinmortsell
Copy link
Contributor Author

Having looked at the datasheet the baudrate calculation needs to be done separately for asynchronous modes and synchronous modes. (And for ISO7816, should that ever be implemented.)
Furthermore, Baudrate Configuration should be omitted completely for SPI Client as the clock speed is determined by an external chip in that case.

@tmplt tmplt added the bug Something isn't working label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants