This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hey guys, I am trying to pass a delay in micro seconds to the tiva tm4c123g processor vis SysCtlDelay(); I am trying to pass a 40 micro second delay using the function but then the processor enter the exception handler. What might be the reason for this? How can I pass micro second delays on tm4c? I need it to interface dht22 temp and humidity sensor???
Actually sysctldelay works fine. The problem is I want to send a microsecond delay. But some how it doesn't accept it. Is there a way to pass such a delay? I believe sysctldelay send the delay in milliseconds
Hey Robert,
here is the code block which doesn't work
#define DHT22 RHT03
#define MY_PIN_PERIPH SYSCTL_PERIPH_GPIOE
#define MY_PIN_PORTBASE GPIO_PORTE_BASE
#define MY_PINNR GPIO_PIN_3
#define MCU_Clock 12500000
#define MY_TIMER_PERIPH SYSCTL_PERIPH_TIMER0
#define MY_TIMERBASE TIMER0_BASE
#define MY_TIMER TIMER_B
#define MY_TIMEOUT (MCU_Clock/4000)
#define DHT_WAIT_40us ((MCU_Clock*40)/1000000000000)
#define DHT_WAIT_50us ((MCU_Clock*50)/1000000000000)
#define DHT_WAIT_70us ((MCU_Clock*70)/1000000000000)
#define DHT_WAIT_80us ((MCU_Clock*80)/1000000000000)
#define DHT_WAIT_90us ((MCU_Clock*90)/1000000000000)
To be noted : SysCtlClockGet(); returns a value of 12.5 MHz which I use to set all my future delays.
Now this statement doesn't work and debug goes to exception handler and stays there forever.
SysCtlDelay(DHT_WAIT_40us );
Now DHT_WAIT_40us means a 40 microsecond value. passing that hangs the code in a limbo.
Question is: can I use such microsecond values in sysctl delay. if not , what are the alternatives. I am using a dht22 sensor and its data sheet requires a 40 us delay etc.
Here is the data sheet, maybe you can suggest me some better ways to implement the delays.
Let me know if you want more code .
Thank you for your patience :)
Regards,
Keyshav
Here is the data sheet, maybe you can suggest me some better ways to implement the delays.
To be blunt - this is not a datasheet, but a heap of crap.
In your place, I would try to contact the given e-mail address. Is the protocol SPI or SPI-like ? Isn't this 40us number not just a minimum ?
Keyshav Mor said:btw, the email adress is kaput. no mail gets delivered to it.as i said. its chinese. no reliablity
Just click on "Example code" under documents. For whatever reason this code comes as a M$-Word document is beyond me ...
My contention in this case is not only the "crappiness" of the datasheet (form, data, spelling, ...), but the suspected incorrectness. That "40us" might just be a minimum, and can easily be replaced by, say, 400us or 1ms, very much easing the requirements for mentioned (troublesome) delay code. And for getting a peripheral part (like a sensor) up and running, I don't start with the specified minimum timing anyway.
I would have no problem using discontinued part in my one-shot-private projects. I hope the O.P. is aware that chances for replacement might go to NIL. For a commercial project, I wouldn't consider it even for a moment...
Bruno Saraiva said:I don't think the function crashes if you pass 0 (assuming the compiler will convert the result to integer...)
I will be zero provided the prototype is in scope (if not there should be compiler warnings) or the compiler is broken
Bruno Saraiva said:#define MCU_ClockDiv3 12500000/3
Two things
#define CLOCKS_PER_LOOP 3
#define MCU_CLOCK 12500000
#define MS_TO_LOOP_MACRO(ms) (((ms)*MCU_CLOCK)/(CLOCKS_PER_LOOP*1000))
Note that this limits ms to INT_MAX/MCU_CLOCK before you have an overflow issue. You will need to check against that somewhere. If that is potentially an issue you can change to
#define MS_TO_LOOP_MACRO(ms) ((int)(((ms)*(double)MCU_CLOCK)/(CLOCKS_PER_LOOP*1000.0)))
This will reduce to a constant int value when ms is a constant (not const) but will have a floating operation or two if ms is a variable.
Robert
Those are untested macros, I may well have slipped a bracket or introduced a typo.
Not really IMHO. Its not a delay function, but you could build one around it. And it obviously only millisecond resolution.
It also conveys the impression that the sensor can be driven with a much slower timing than you are initially suggested (milliseconds instead of microseconds). Didn't try this myself, though.
And I would put Arduino in the same category as this sensor ...
f.m., I agree with you and even started a discussion some time ago "against Lazuinos". But it is good to see that Keyshav is trying to free himself from that beast, ain't it?
And finally, may I suggest that you don't keep different matters in one same thread, as it will be useless for others looking for the second subject in the future? New question? New thread, with a nice and clear title if possible!
I interpret the question about Arduino (or an Arduino function) as attempt of the O.P. to interpret some Arduino example code for this sensor, to reimplement within his (TivaWare based) project.
That would make sense, and starting another thread would just complicate things...
My suggestion for a new thread is that, essentially, his recent post contains a new question: "How to keep Tiva system up time?".
The Arduino function mentioned is just a reference, and at this point is not really the theme...