Giter Site home page Giter Site logo

m_sdhc_baudrate caculation wrong about usdfs HOT 2 OPEN

manitou48 avatar manitou48 commented on August 30, 2024
m_sdhc_baudrate caculation wrong

from usdfs.

Comments (2)

WMXZ-EU avatar WMXZ-EU commented on August 30, 2024

I believe that the following code should be correct

// get dividers from requested baud rate 
	uint32_t aux=F_CPU;
	uint32_t ii=0,jj=1;
	uint32_t baudrate=kbaudrate*1000;

	while(aux/(16*(1<<ii))>baudrate) ii++;
	while(aux/(jj*(1<<ii))>baudrate) jj++;

	uint32_t minpresc=ii;
	uint32_t mindiv=jj-1;

	m_sdhc_baudrate=F_CPU/((1<<minpresc) * (mindiv+1));

	// Change dividers
	sysctl = SDHC_SYSCTL & 
			(~ (SDHC_SYSCTL_DTOCV_MASK | SDHC_SYSCTL_SDCLKFS_MASK | SDHC_SYSCTL_DVS_MASK));
	SDHC_SYSCTL = sysctl | 
			(SDHC_SYSCTL_DTOCV(0x0E) | SDHC_SYSCTL_SDCLKFS(minpresc) | SDHC_SYSCTL_DVS(mindiv));

presc is a single bit and div is a number

This includes the (untested case) that presc = 0 is valid input and that presc=0 does not prevent div to be effective.
The way I calculate is if F_CPU=96 Mhz and baudrate is 3 kHz then ii=1 and jj=16
presc=1 and div = 15 and therefore 96MHz/((1<<presc)*(div+1)) = 3kHz

Can you agree?

from usdfs.

manitou48 avatar manitou48 commented on August 30, 2024

from usdfs.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.