Sunday, 16 July 2017

Monday, 26 June 2017

Brief Explanation for UART RS232 SPI I2C


Reference : https://electronics.stackexchange.com/questions/37814/usart-uart-rs232-usb-spi-i2c-ttl-etc-what-are-all-of-these-and-how-do-th



Serial is an umbrella word for all that is "Time Division Multiplexed", to use an expensive term. It means that the data is sent spread over time, most often one single bit after another. All the protocols you're naming are serial protocols.

UART, for Universal Asynchronous Receiver Transmitter, is one of the most used serial protocols. It's almost as old as I am, and very simple. Most controllers have a hardware UART on board. It uses a single data line for transmitting and one for receiving data. Most often 8-bit data is transferred, as follows: 1 start bit(low level), 8 data bits and 1 stop bit(high level). The low level start bit and high level stop bit mean that there's always a high to low transition to start the communication. That's what describes UART. No voltage level, so you can have it at 3.3 V or 5 V, whichever your microcontroller uses. Note that the microcontrollers which want to communicate via UART have to agree on the transmission speed, the bit-rate, as they only have the start bit's falling edge to synchronize. That's called asynchronous communication.

For long distance communication (That doesn't have to be hundreds of meters) the 5 V UART is not very reliable, that's why it's converted to a higher voltage, typically +12 V for a "0" and -12 V for a "1". The data format remains the same. Then you have RS-232 (which you actually should call EIA-232, but nobody does.)

The timing dependency is one of the big drawbacks of UART, and the solution is USART, for Universal Synchronous/Asynchronous Receiver Transmitter. This can do UART, but also a synchronous protocol. In synchronous there's not only data, but also a clock transmitted. With each bit a clock pulse tells the receiver it should latch that bit. Synchronous protocols either need a higher bandwidth, like in the case of Manchester encoding, or an extra wire for the clock, like SPI and I2C.

SPI (Serial Peripheral Interface) is another very simple serial protocol. A master sends a clock signal, and upon each clock pulse it shifts one bit out to the slave, and one bit in, coming from the slave. Signal names are therefore SCK for clock, MOSI for Master Out Slave In, and MISO for Master In Slave Out. By using SS (Slave Select) signals the master can control more than 1 slave on the bus. There are two ways to connect multiple slave devices to one master, one is mentioned above i.e. using slave select, and other is daisy chaining, it uses fewer hardware pins (select lines), but software gets complicated.

I2C (Inter-Integrated Circuit, pronounced "I squared C") is also a synchronous protocol, and it's the first we see which has some "intelligence" in it; the other ones dumbly shifted bits in and out, and that was that. I2C uses only 2 wires, one for the clock (SCL) and one for the data (SDA). That means that master and slave send data over the same wire, again controlled by the master who creates the clock signal. I2C doesn't use separate Slave Selects to select a particular device, but has addressing. The first byte sent by the master holds a 7 bit address (so that you can use 127 devices on the bus) and a read/write bit, indicating whether the next byte(s) will also come from the master of should come from the slave. After each byte receiver must send a "0" to acknowledge the reception of the byte, which the master latches with a 9th clock pulse. If the master wants to write a byte the same process repeats: the master puts bit after bit on the bus and each time gives a clock pulse to signal that the data is ready to be read. If the master wants to receive data it only generates the clock pulses. The slave has to take care that the next bit is ready when the clock pulse is given. This protocol is patented by NXP(formerly Phillips), to save licensing cost, Atmel using the word TWI(2-wire interface) which exactly same as I2C, so any AVR device will not have I2C but it will have TWI.

Two or more signals on the same wire may cause conflicts, and you would have a problem if one device sends a "1" while the other sends a "0". Therefore the bus is wired-OR'd: two resistors pull the bus to a high level, and the devices only send low levels. If they want to send a high level they simply release the bus.

TTL (Transistor Transistor Logic) is not a protocol. It's an older technology for digital logic, but the name is often used to refer to the 5 V supply voltage, often incorrectly referring to what should be called UART.


Difference between USB and USB CDC and other USB standards



HID (Human Interface Device) generally requires no Drivers to be installed by the User
It is limited to 64 Bytes/ms (~64K/second) per endpoint used
It is guaranteed to get the timeslot because it uses INT transfers.

CDC (Comunication Device Class) requires drivers (INF file) to be installed and then simulates a serial port.It uses Bulk transfers so theoretically can have good bandwidth but is NOT guaranteed
There are also other code and packet overheads involved. USB CDC can work as UART.

Various USB standards

  • The USB 3.1 Specification released on July 26, 2013 and ECNs approved through February 15, 2017
  • USB 3.1 Appendix E:  Repeaters
  • USB 3.0 Adopters Agreement
  • On-The-Go and Embedded Host Supplement to the USB Revision 3.0 Specification Revision 1.1 as of May 10, 2012
  • Inter-Chip Supplement to the USB Revision 3.0 Specification, Revision 1.02 as of May 19, 2014
  • USB 3.1 Device Class Specification for Debug Devices as of July 14, 2015
  • USB Type-CTM Locking Connector Specification, March 9, 2016
  • USB Type-CTM Cable and Connector Specification Revision 1.2, March 25, 2016 and ECNs
  • USB Type-CTM Port Controller Interface Specification as of November, 2016
  • USB Power Delivery Specification Rev. 2.0, Version 1.3 is available at http://www.usb.org/developers/powerdelivery/
  • USB Power Delivery Specification Rev. 3.0, Version 1.1, January 12, 2017, and corresponding Adopters Agreement
  • USB Authentication Specification Rev. 1.0 with ECN and Errata through February 2, 2017


 There are 5 modes of USB data transfer, in order of increasing bandwidth: Low Speed (from 1.0), Full Speed (from 1.0), High Speed (from 2.0), SuperSpeed (from 3.0), and SuperSpeed+ (from 3.1); modes have differing hardware and cabling requirements. USB devices have some choice of implemented modes, and USB version is not a reliable statement of implemented modes. Modes are identified by their names and icons, and the specifications suggests that plugs and receptacles be colour-coded (SuperSpeed is identified by blue).



References : 
  •   WIki
  •   https://cscott.net/usb_dev/data/devclass/usbcdc11.pdf
  •   http://www.usb.org/developers/docs/
  • http://www.microchip.com/forums/m420851.aspx

Tuesday, 13 December 2016

Netsh command to disable IPv4 Autoconfiguration in Windows 10/ Windows 8

  1. Open Windows command prompt in administrator mode.
  2. At the command prompt type: netsh winsock reset catalog and press [Enter].
  3. Next type: netsh int ip reset reset.log and press [Enter].
  4. Restart your PC for the changes to take effect.

Wednesday, 18 May 2016

PERL example for opening EXCEL sheet using WIN32:OLE

#!/usr/bin/perl
# This PERL file will open one EXCEL, create 4 WORK Sheets, in first
# WORKSheet make table with borders and few values

use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;                                # die on errors...
my $Excelfile = Win32::OLE->GetActiveObject('Excel.Application')
                || Win32::OLE->new('Excel.Application', 'Quit'); 
$Excelfile->{DisplayAlerts} = 0;
$Excelfile->{ScreenUpdating} = 0;

$workbook = $Excelfile->Workbooks->Add();

for ($j=1;$j<=4;$j++)
{   
    $worksheet = $workbook->WorkSheets->Add({after => $workbook->WorkSheets($workbook->WorkSheets->{COUNT})});
    $worksheet->{Name}="Summary_".$j;
}
my $cur_dir = `cd`;
chomp($cur_dir);
$TargetFile = $cur_dir."\\Excel_Test_File.xls";
print "Result file name is $TargetFile \n";


#Select first sheet and write values

$worksheet=$workbook->WorkSheets("Summary_1");

$current_row = 3;
$start_row_forborder=$current_row;
$current_col = 2;

#for ($k=0;$k<3;$k++)
#{
#
#    $worksheet->Cells($current_row,$current_col)->Font->{FontStyle}="Bold";
#    $worksheet->Cells($current_row,$current_col)->Interior->{ColorIndex} =24;
#    $worksheet->Columns($current_col)->{ColumnWidth}=20;
#    $current_col++;
#
#}

### Another way of formatting if we are using fixed columns

$worksheet->Range("B$current_row:D$current_row")->Font->{FontStyle}="Bold";
$worksheet->Range("B$current_row:D$current_row")->Interior->{ColorIndex} =24;
$worksheet ->Range("B$current_row:D$current_row") ->{ColumnWidth} = 20;

#$current_col=$current_col-3;
$worksheet->Cells($current_row, $current_col)->{'Value'} = "S.No";
$worksheet->Cells($current_row, $current_col+1)->{'Value'} = "Name";
$worksheet->Cells($current_row, $current_col+2)->{'Value'} = "Department";
$worksheet->Cells($current_row, $current_col+2)->{'Value'} = "Work_type";

$current_row++;

for ($i=1;$i<=10 ;$i++) {

    $worksheet->Cells($current_row, $current_col)->{'Value'} =$i;
    $worksheet->Cells($current_row, $current_col+1)->{'Value'} = "Name_".$i;
    $worksheet->Cells($current_row, $current_col+2)->{'Value'} = "Colour";
    $current_row++;
}

$last_row=$current_row-1;
    #### Keep border for excel if it is last line.

    $worksheet->Range("B$start_row_forborder:D$last_row")->{HorizontalAlignment} = xlHAlignRight;
    $worksheet->Range("B$start_row_forborder:D$last_row")->{Borders}->{Weight} = xlThin;
   


#Deleting Default SHEETS
$worksheet = $workbook->Worksheets("Sheet1")->Delete();
$worksheet = $workbook->Worksheets("Sheet2")->Delete();
$worksheet = $workbook->Worksheets("Sheet3")->Delete();

$workbook->Worksheets(1)->Activate;


$workbook->SaveAs("$TargetFile");
$workbook->Close;


Monday, 9 May 2016

Syntax error in /sysroot/etc/selinux/config : 6 : syntax error ";" unexpected failed to boot sleeping forever.

We got this issue in one of the Linux PC, by mistake in the config file of SELinux instead of using # for commenting ";" was used. After reboot the PC won't boot with below messages:

 

===============================
/sysroot/etc/selinux/config : 10 : syntex error: ";" unexpected
Signal caught!
Boot has failed, sleeping forever.
===============================

We can access GRUB command line but Single mode bootup doesnt work. the only way to recover was to use Live CD, go to rescue mode. Give below command in shell:

chroot /mnt/sysimage
cd etc/selinux
vim config

Modify the statement and save and reboot.

And it worked....

Keep Working , Keep Trying !!


Friday, 22 April 2016

Windows "Netsh" command to change Interface Dynamic to Static IP address



netsh interface ip set address name="Local Area Connection" source=static 10.10.1.1 255.0.0.0


netsh interface ip set address name="Local Area Connection" source=dhcp
Related Posts Plugin for WordPress, Blogger...