Thursday, 8 September 2016

Arduino -Peripheral Test Source code for SPI, I2C,GPIO, PWM,ADC


This file can be downloaded here ...

https://drive.google.com/drive/folders/0B02sL8YIqsjCeE9Db0RFQlFWdEk?usp=sharing

Enable macros to test ...

#include <Wire.h>
#include <SPI.h>

//#define LED_TEST
//#define ADC_TEST  // Pin A0 VCC, GND
//#define GPIO_TEST
//#define PWM_TEST
//#define I2C_TEST //A4 (SDA) and A5 (SCL)
#define SPI_TEST //SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK)


#ifdef SPI_TEST
#define spi_readwrite SPI.transfer
#define spi_read() spi_readwrite(0x00)

int  mcp2515_readRegister(const int  address)                                                                  
{
    int  ret;
int MCP_READ=45;
//    MCP2515_SELECT();
    spi_readwrite(MCP_READ);
    spi_readwrite(address);
    ret = spi_read();
  //  MCP2515_UNSELECT();

    return ret;
}

#endif


#ifdef I2C_TEST
#define I2C_ADDRESS 0x50
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Wire.endTransmission();
  delay(5);
}

byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
  byte rdata = 0xFF;
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,1);
  if (Wire.available()) rdata = Wire.read();
  return rdata;
}
#endif


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
#ifdef LED_TEST
  pinMode(13, OUTPUT);
#endif

#ifdef GPIO_TEST
  pinMode(2, OUTPUT); //D2
  pinMode(12, OUTPUT);//D12
  pinMode(13, OUTPUT);//D13
#endif
 SPI.begin();

}

void loop() {
  // put your main code here, to run repeatedly:
#ifdef LED_TEST
  digitalWrite(13, HIGH);
  delay(1000);          
  digitalWrite(13, LOW);  
  delay(1000);            
#endif
#ifdef ADC_TEST
 int sensorValue = analogRead(A0);
 Serial.println("value");
 Serial.println(sensorValue);
 delay(1);  
#endif
#ifdef GPIO_TEST
  digitalWrite(2, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(13, HIGH);
  delay(1000);          
  digitalWrite(2, LOW);
  digitalWrite(12, LOW);
  digitalWrite(13, LOW);
  delay(1000);            
#endif
#ifdef PWM_TEST
  analogWrite(9, 235);//pin D9
#endif
#ifdef  I2C_TEST
writeEEPROM(I2C_ADDRESS, 45, 123);
#endif
#ifdef SPI_TEST
{
mcp2515_readRegister(33);
}
#endif
}

Monday, 29 August 2016

Orange Pi Bare Metal code


I did some work on this .. Now the Orange Pi bare metal code is ready ..


This is tested for Orange Pi Pc , Other boards should also work  ..


// Procedure

1. write any orange pi Linux OS to the SD Card , I have used Lubuntu_1404_For_OrangePiPC_v0_8_0_.img
 This will write the bootloader in proper place .
 ( this method is pretty simple , otherwise you have to use linux & write the bootloader in the particular
 partition)
2. Copy the "blink.bin" in the fat partition, same folder where  "script.bin" & "uimage" is present 
 (you can use any windows/linux OS )  
3. Connect USB-UART to the orange Pi , open serial putty  (use  http://www.putty.org/ or any serial
 application )
4. Power ON ,  now you can see boot messages in the putty screen , press any key immediately,   
this will stop the control goes to linux ..
5. Now you can see "sunxi#" prompt  , enter the below command  
     fatload mmc 0 0x41000000 blink.bin; go 0x41000000
6. Now ""hello world " message appears ..





compiling  , I use gcc-arm-none-eabi-4_7-2013q3-20130916-win32.exe , on windows

just "make" 

code , refer the attachment 


unsigned int count=0;

int notmain ( void )
{
    
        uart_print("Hello world \n");
        while(1)
        {
                if(count)
                {
              PUT32(PIO_BASE+PA_DATA_REG, 1<<15); //pa15 red led refer schematics 
                  count=0;
                }
                else
                {
                  PUT32(PIO_BASE+PA_DATA_REG, 0);
                  count=1;
                }
            uart_send(uart_recv());  // wait till it gets new char  -  echo 
        }
    return(0);
}

many thanks to David Welch ,  this code is based on his bare metal code .. 


I would love to add additional functionalities like , GPIO , SPI ,I2C ,Timer ,PWM , Interrupts ,Display ..


Once its added we can easily port to other Embedded OS ,  like , FreeRTOS  , Windows CE & QNX 


One major good thing with this Allwinner H3 board is , it has "ehci" "ohci" USB stack , which is very

 easy to port  .
. thats where raspberry pi fuckked up , designware OTG(raspberry uses)  has no documentation & 
hard to implement ..

https://drive.google.com/file/d/0B02sL8YIqsjCd21BR0Q3d0ljdW8/view?usp=sharing

Sunday, 26 June 2016

Raspberry Pi - QNX update -3

QNX seems working well on this platform .. looks to be fast ..

Bug in the serial driver is fixed after extensive work ..

Next

1. Make it to receive input commands (serial drive input side )
2. Interrupt -serial

Hopefully it will be over today & shifting my attention towards

Raspberry PI SPI Touch ..

There after work will be ceased for a while then develope beaglebone  QNX graphics driver HDMI

Hopefully if these are completed by July

Meanwhile I am planning orange PI bare metal also ...  Yes some times later a full fleged qnx , wince os for orange pi is possible ..   May be after the end of raspberry & beaglebone work

This product is low cost one so no one will be willing to buy the code ... More over only very few people have QNX or WinCE .. if he has money he will do it with beagle bone , it has both the OS support ...

So It will be open source , same QNX apache license  ...  I may request some donation  , not for the work/time but for the hardware cost & further research  :)  ..



Saturday, 25 June 2016

Raspberry pi QNX update -2

Kernel is up , Some bug in the serial driver....... yeyyyyyyyyyyy ... yes ...  yes  ... yes


Sunday, 19 June 2016

Improving RTL SDR RTL2832U Signal reception - Antenna techniques - Making it better than your Normal Radio

Refer my previous article for receiving MW & SW signal ....  No compnent required , just a basic soldering skill required.



http://ihaack.blogspot.in/2015/11/rtl-sdr-am-radio.html


1. MW, SW reception , add as much as wire , so that you could get a better reception ..
Here we are using direct sampling method .. Using this method we can receive up to 14MHz

2. Earth/Ground is important for MW/SW reception ,so connect your laptop to the power adapter ..
    You can either power ON ,or just keep it off,  this will ensure that you get better reception ..

I keep 2 exe files, one for receiving 0-14MHz range ,other for 14MHZ -> rest



For VHF Reception


1. The wire & the antenna comes with this product is the signal spoiler , Chinese are not willing to improve the quality ... so its our responsibility .. Cut the wire ,bit close to the connector .. Yes cut it , dont think about it , just cut it , this will improve the signal strength by atleast 10 times .. guaranteed...







2. Now you could see a sheild wires  & center cable ..

take 2 pieces of 1 meter or 1 1/2 meter cable , connect those to cable to these two ends , the other 2 ends have to be joined together , this would match the impedance better

Now you can see a drastic improvement in the quality of reception ...

With these 2 changes you could listen to all channels without any trouble ..

This information is provided under MIT license :)

I will post few videos on this 

Tuesday, 31 May 2016

Tamilnadu /Tamil Radio frequencies

This reception is with respect to Tirunelveli/Short wave receptions can be heard all over Tamilnadu

MW service 
1. 1197KHz - Tirunelveli Radio
2. 1053KHz- Tutucorin 

Tropical /Short wave Radio 
chennai 
05.45 a.m. - 08.15 a.m. 4920KHz
08.30 a.m. - 10.00 a.m. 7380KHz
11.40 a.m. - 03.00 p.m. 7380KHz
05.30 p.m. - 11.10 p.m. 4920KHz

BBC
12.830KHz  -9.15pm -9-30PM

China Radio
13600-9570KHz 7.30-9.30 Morning & Evening

Over seas service to lanka
0530-0615 - 1053  7270 9835 11985 
0530-0615 - 11740 13795
0645-0900 - 1053
1630-1645 - 1053
1645-1745 - 1053 7270 17510 
1645-1745 - 1134 9810 13695
1745-1830 - 1053
2030-2100 - 1053
sinchala 
1830-2030 --  1053 7270 9820 15050 (DRM)  

FM 
1. 101- Nagercoil
2.100.5-Kodai
3.102.6 Tiruneleli
4.93.5 Surian FM
5.106.4 Hello FM


English
GOS.IV (English) 2315-0115 11935 13695 17670
GOS.IV (English) 2315-0115 9445 11580 
                              2315-0115 7550 (DRM) 9950 (DRM) 11670
GOS.V (English) 0215-0400  9910 11620 11740
                             0215-0400  7550 (DRM) 9445 9950 (DRM) 11670 
GOS.I (English) 0415-0615  11645 (DRM) 13605 (DRM) 
GOS.II (English) 1530-1630  15030 15410 13605
GOS.III (English) 1900-2030 9690 11620 13710  

Thursday, 5 May 2016

USB Driver Development - Windows

There are many low cost controllers/ development boards  have USB support


1. STM32f4_discovery  



2. TM4c123
     


3.PSOC5 

They have buildin pheripherals like I2C, SPI, UART , CAN ... Making a protocol converter/ other controllers using these devices makes the price compatative ..

There are 4 ways one can write driver to these devices

1. Libusb 
2.WinUSB
3.Custom Drivers
4.CDC /Serial Driver

Libusb 
             Libusb is best for devices which requires support to other OS like Linux , MAC OS , BSD ..
It maintains common calling conventions & data structures across defferent platforms .. 

Application 
       |
User Mode Driver (dll)
       |
Kernel Mode Driver (Sys)
       |
USB Host Driver (Comes along with OS)


WinUSB 
            WinUSB only work with Windows platform .. 

Application 
       |
User Mode Driver (dll)
       |
Kernel Mode Driver (Sys)
       |
USB Host Driver (Comes along with OS)

Custom Drivers :
              Instead of using the above two drivers one can prefer to write a custom driver & maintain proprietary  issues , avoid exposing the data transfer format/ protocol .. [Still some one can hook a  USB analyser & see whats happening ]

Application 
       |
User Mode Driver (dll)
       |
Kernel Mode Driver (Sys)
       |
USB Host Driver (Comes along with OS)


Virtual Serial Driver :
              This way one can avoid supplying a driver for the device & use the pre-supplied windows USB class drivers ..

Application 
       |
Serial Port Accessing Interface 

Red Color Shows work required to do... Green - driver /Software already available ..