I have some projects using the 16 bits timer/counter of an Atmega128,
and I finally used all bits timer/counter 1 and 3.
I need more 16 bits timer/counter, so I just thought about using the pin T1 or T2. I recognized that these PINs do exist for getting an external clock signal, don't they?
Related
I have an RDM6300 RFID writer/reader. It can read RFID Tags and it sends the data via UART to a microcontroller. So far I worked with multiple Microcontrollers from which ones the STM32F04 had the most UART "ports" (8 transmitters and receivers). The Arduino has got a few, but it is not enough.
I want to have 25 RFID readers (that are reading almost at the same time), but I can't find a way to send data from all the readers to one microcontroller.
Is there a way how can I connect 25 readers to ONE microcontroller?
You have 25 things transmitting at 9600 bps. You have an MCU running at 180 MHz with 8 UARTS and lots of timer capture channels (32 channels, 30 of them usable on the 100 pin STM32F427VITx). 8 of the 25 inputs are taken care of by the UARTS, 17 needs to be processed by other means. Connect them to timer capture channels.
The MCU runs at 180 MHz, the inputs change state at 9600 Hz, that means 18750 clock cycles between events. Should be way more than enough to process all of them, if you don't use HAL.
read the timer status register, check for capture events and clear them
check pin state, low means start of a frame
store the capture register value for that channel
keep checking for capture events
if there is one, clear it
read the capture timestamp, subtract the stored value from step 3 from it
calculate the number of bits received with identical state
keep doing it until you have 9 bits (start bit + 8 data bits) and high input on the pin
Do the above in parallel for all 17 channels. You need a suitable prescaler for the timers so they won't overflow while reading a full frame (9*18750=168750 cycles)
When I write 8 bit in hc595 shift register, with i2c last bit go to Q0 in second hc595.
Why?
Schematic:
My code:
i2c_write(0b10101010);
latch_led_sensors_out();
delay_ms(200);
It's because of the I2C protocol. Even though you want to send out 8 bits, you are really sending out 9. The way I2C works is the initial frame contains 7 (or 10) bits of address, plus one bit for read/write. After those initial 8 bits are clocked out, the master sends an additional clock pulse to read in the ACK/NACK bit from the slave device. Remember, the master controls the clock, even when the slave is driving the data pin.
I'm trying to implement the firmata protocol and having a bit of a difficult time deciphering the spec for writing digital pins:
I have noted the following parts of the spec of Firmata 2.3
* type command channel first byte second byte
------------------------------------------------------------------------------
* digital I/O message 0x90 port LSB(bits 0-6) MSB(bits 7-13)
and
/* two byte digital data format, second nibble of byte 0 gives the port number (e.g. 0x92 is the third port, port 2)
* 0 digital data, 0x90-0x9F, (MIDI NoteOn, but different data format)
* 1 digital pins 0-6 bitmask
* 2 digital pin 7 bitmask
*/
I'm having some difficulty interpreting the spec. I've looked at other implementations, but haven't been able to see the relationship between the spec and implementation.
So let's say I am wanting to turn on the Arduino LED (pin 13), I know it will be on the second port, port 1, so the first byte will be #{91}.
I'm getting confused about the bitmask for the second two bytes though. I know what a bitmask is, so I want to enable the right bit for the pin.
Why is the bitmask so large for the digital pins? I'm familiar with using bitmasks on the digital outputs of PLCs, which seems much different (one pin, one bit)
My thought is that pin 13 would be the 7th pin on port 1. Since I don't care about the other pins, I would mark the pin in the 2nd byte #{40} and I don't need any pins set for the third byte #{00}?
I don't think my interpretation of the bitmasks is correct, and it's probably where my error is
Am I on the right track for this? Is this the right command for setting a pin high or low?
After some strace debugging with the firmata test application, I discovered the simple command to turn on Pin 13 was:
#{912000}
and to turn it off:
#{910000}
I'm trying to talk serial with an SDI-12 device, and it requires inverted seven data bits, even parity and one stop bit (7E1) serial at 1200 baud.
From the datasheet:
SDI-12 communication sends characters at 1200 bits per second. Each character has 1 start bit, 7 data bits (LSB first), 1 even parity bit, and 1 stop bit (Active low or inverted logic levels):
All SDI-12 commands and response must adhere to the following format on the data line. Both the command and response are preceded by an address and terminated by a carriage return line feed combination.
Is this possible with the Serial or SoftwareSerial libraries? I am trying to avoid additional hardware (beyond a levelshifter to 3.3 V), but I will do so if it is the only way.
I have seen that SoftwareSerial can do inverted, and Serial can do 7E1, but I can't find if either can do both.
I have access to a Arduino Mega (R2), and Arduino Uno (R3).
Here is the device I want to communicate with: http://www.decagon.com/products/sensors/soil-moisture-sensors/gs3-soil-moisture-temperature-and-ec/ and here, http://www.decagon.com/assets/Uploads/GS3-Integrators-Guide.pdf is the document explaining the protocol. Page 6 talks about its implementation of SDI.
I'm not familiar with Arduino, however the SDI-12 physical layer is inverted from the standard TTL levels - probably for two reasons:
Since the idle voltage is 0V, this results in lower standby power (due to nominal pull-down resistors in a typical SDI-12 sensor.
It facilitates simple bus 'sniffing' using a standard RS-232 serial port.
Short of bit-banging a 5V IO pin - yes, if using a standard microcontroller UART you will need an external inverter (or 2) and a 3-state buffer. Possibly requiring level shifting, depending on your hardware.
Thumbs down to the Wikipedia entry - SDI-12 uses entirely standard UART bit timings (very much like RS-232), just different signal levels (0 - 5V); see point #2. However, there are specific break sequences and strict timing requirements, which makes firmware development more difficult.
If you are serious about SDI-12 firmware development, you may want to invest in an SDI-12 Verifier. A thorough study of the specification is essential.
A little late... but better late than never
I have actually just written a library for exactly that (actually exactly that including the sensors ... so it should work exactly with the included examples )
https://github.com/joranbeasley/SDISerial (Arduino Library)
#include <SDISerial.h> //https://github.com/joranbeasley/SDISerial (Arduino Library)
#include <string.h>
#define DATA_PIN 2
SDISerial connection(DATA_PIN);
char output_buffer[125]; // just for uart prints
char tmp_buffer[4];
char sensor_info[]
//initialize variables
void setup(){
connection.begin();
Serial.begin(9600);//so we can print to standard uart
//small delay to let the sensor do its startup stuff
delay(3000);//3 seconds should be more than enough
char* sensor_info = connection.sdi_query("0I!",1000); // get sensor info for address 0
}
//main loop
void loop(){
//print to uart
Serial.println("Begin Command: ?M!");
//send measurement query (M) to the first device on our bus
char* resp = connection.service_request("0M!","0D0!");//Get Measurement from address 0
sprintf(output_buffer,"RECV: %s",resp?resp:"No Response Recieved!!");
Serial.println(output_buffer);
delay(10000);//sleep for 10 seconds before the next read
}
I am working on GSM sim900D interfacing with Atmega16. Initially I made the circuit using MAX232 on breadboard. Then I connected it to my PC using a serial port. I tested AT commands, the commands worked perfectly on hyper terminal and I was able to send SMS using hyperterminal. Then I tested it on Proteus and it was working there perfectly too.
I am using codevision avr as the compiler. GSM work on 9600baud but the problem is that in compiler I have to keep the baud rate4800(clock = 1MHz) and at proteus COMPIM(physical baud=9600 & virtual baud=4800) only then it works when I run it on hardware(breadboard) it doesn't work as I have set the baud to 4800. I don't know how to set the baud for hardware. I tried 9600baud for hardware in compiler but it doesn't send SMS at all. Kindly tell me what I should do?
On ATmega16 (and other ATmegas), the serial baud rate is set via UBRRH and UBRRL registers plus the U2X bit in the UCSRA register. The detailed description of how this works starts on page 146 of the ATmega16 datasheet. Basically, UBRR is a 16-bit register and so must be accessed separately via 8 bit parts UBRRH (the high byte) and UBRRL (the low byte). The value you want to put into these registers (and the U2X bit in UCSRA register) depends on
the clock rate
the desired baud rate.
For 1Mhz clock and 9600 baud there are two options (see table 68 on page 168 in the datasheet): cleared U2X bit and UBRR set to 6 or set U2X and UBRR set to 12. The latter option results in a baud rate generation that is closer to the desired baud rate (0.2%) error, therefore, the latter option is recommended. Consequently, the code you want is:
UBRRH = 0;
UBRRL = 12;
UCSRA |= 1<<(U2X);
There is a nasty gotcha lurking here: as the datasheet states, UBRRH and UCSRC are the same register. UCSRC controls parity, stop bits, and other important settings. Therefore if you ever need to write to UCSRC, make sure that you set the URSEL bit at the same time:
UCSRC = (1<<URSEL) | (...other bits...)
or
UCSRC |= (1<<URSEL) | (...other bits...)
Otherwise you will clobber your UBRRH register and wonder why your baud rate is not what you expected.
But you can also make use of the AVR Libc code, which provides a read-made way for setting a baud rate on AVR, see util/setbaud.html
you check data sheet the error rate is too high. when you using 9600 baud rate on 1MHZ this is the main problem . take 8,12,16 MHZ as possible and check data sheet . and dont forget to burn fuse bits related to XTAL frequency if you not burn these bits properly that relate with crystal that is not work properly .
if u need more help ask..