Wednesday, July 10, 2013

Programming ATMEGA328-AU and other non-P type on Arduino using USBasp.

I am searching for the fix on programming ATMEGA328-AU on arduino board using USBasp. It turns out that I need to modify avrdude.conf file to much the signature. This link present the solution.


This is the error I get,

avrdude: Expected signature for ATMEGA328P is 1E 95 0F Double check chip, or use -F to override this check.

To fix this, I as metioned on the above link, I need to modify the avrdude.conf file located here,

C:\Program Files\Arduino\hardware\tools\avr\etc

I need to modify the signature entry of ATMEGA328P from,

#------------------------------------------------------------
# ATmega328P
#------------------------------------------------------------
part
    id = "m328p";
    desc = "ATMEGA328P";
    has_debugwire = yes;
    flash_instr = 0xB6, 0x01, 0x11;
    eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00,
 0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF,
 0x99, 0xF9, 0xBB, 0xAF;
    stk500_devcode = 0x86;
    # avr910_devcode = 0x;
    signature = 0x1e 0x95 0x0F;
    pagel = 0xd7;
    bs2 = 0xc2;
    chip_erase_delay = 9000;
    pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";

 to,

#------------------------------------------------------------
# ATmega328P
#------------------------------------------------------------
part
    id = "m328p";
    desc = "ATMEGA328P";
    has_debugwire = yes;
    flash_instr = 0xB6, 0x01, 0x11;
    eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00,
  0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF,
  0x99, 0xF9, 0xBB, 0xAF;
    stk500_devcode = 0x86;
    # avr910_devcode = 0x;
    signature = 0x1e 0x95 0x14;
    pagel = 0xd7;
    bs2 = 0xc2;
    chip_erase_delay = 9000;
    pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
 "x x x x x x x x x x x x x x x x";

After the change, if I want to use the arduino isp bootloader again, the original signature must be returned. Otherwise if USBasp will be programmer to use(not a the arduino isp bootloader) for programming, new signature must be maintained. 

Saturday, July 6, 2013

Using C# for UART Communication on Microcontrollers and PC.

I will discuss some ways on how to get data from a microcontroller using C#.

The four topics.

1. Initializing Serial Port.
2. Getting a single byte of data.
3. Receiving stream of bytes.
4. Parsing comma separated values.


1. Initializing Serial Port.

Using the toolbox, click on the serial port .

2. Getting a single byte of data.

Even a single byte is useful for simple microcontroller-to-PC Communication. It can act as a signal on when to execute certain action in the software.

3. Receiving stream of bytes.

Receiving stream of data is common to serial port interfacing specially if numerous data is need by the PC. This data can be information form sensors, human input and other sources.

4. Parsing comma separated values.

One of the effective ways of data transimission is thru CSV specially if the information needs to be sorted based on it's class, kind, etc.

Retargeting printf for STM32

Printf has been very useful in transmission of serial data. Here's three steps on how to configure printf for STM32 in KEIL Enviroment.

1.) In you main file, include "stdio.h" header file.

2.) You need to redefine fputc function. See code below.

int fputc(int ch, FILE * f)
{
  /* Transmit the character using USART1 */
  USART_SendData(USART1, (u8) ch);

  /* Wait until transmit finishes */
  while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

  return ch;
}  

3. Lastly, you need to check the Use MicroLib in code generation.

Project -> Options for Target xxxx.. -> Target(tab) --> Code Generation(section) --> Check "use MicroLib"

In addition, I am using E-gizmo STM32 Cortex-M3 Kit for my experiments and test.

Sunday, March 4, 2012

STM32L Discovery Kit

A friend gave me an STM32L-discovery kit. It was my first 32-bit device and packed with the power of ARM-Cortex M3 processor.

My STM32L-Discovery


I will post all updates about my progress using this device.
I already done some experiment with this and I know the adventure with STM32L Discovery will be a long way to go.


Saturday, April 30, 2011

Digital Clock Using PIC16f628a Microcontroller

This is a very basic digital clock that can be done using a microcontroller. I particularly used a PIC16f628a.

You can also check my digital clock based on 74ls90
here --> http://circuitdesolator.blogspot.com/2010/12/digital-clock-based-on-74ls90.html

Here's the picture of my digital clock prototype




This is the schematic of the device:



 Notes to remember:

1. Put resistors from 7447 to the seven segment display pins(a-g) as current limiter resistors
2. You need to start up you're clock at exactly 1200am/pm.



-------------------------------------------SOURCE CODE-----------------------------------------------
//Digital Clock using PIC16f628a microcontroller
//Design by: circuit_desolator
//Date: April 2011

#include<htc.h>

#define _XTAL_FREQ 4000000

__CONFIG(INTIO & WDTDIS & PWRTDIS & UNPROTECT & BORDIS & LVPDIS);

unsigned int hours = 0;
unsigned int mins = 59;

unsigned int timer = 0;
unsigned char mpx_cnt = 0;
static unsigned char mode = 0;

void interrupt ISR(void)
{   
       
            {       
            timer++;
           
            if(timer > 19650)
            {
                mins++;   
                if(mins == 60)
                {           
                    mins = 0;
                    hours++;
                    if(hours == 13)
                    hours == 1;                   
                }
               
                timer = 0;
            }
        }
       
        switch (mpx_cnt)
        {
            case 0:
                PORTB = hours/10;
                RA0 = 1;       
                mpx_cnt = 1;
               
            case 1:
                PORTB = hours%10;
                RA1 = 1;       
                mpx_cnt = 2;
           
            case 2:
                PORTB = mins/10;
                RA2 = 1;       
                mpx_cnt = 3;
           
            case 3:
                PORTB = mins%10;
                RA3 = 1;
                mpx_cnt = 0;
        }
   
        T0IF = 0;                //clear TMR0 interrupt flag   
}


void init_Timers(void)
{
    GIE = 0;               
   
    T0CS = 0;               
    PSA = 0;                                           
    PS2 = 0;              
    PS1 = 0;              
    PS0 = 0;

    T0IF = 0;               
    T0IE = 1;                  
    TMR0 = 6;                                                                                               
   
    GIE = 1;             
}

void main()
{
    TRISA = 0x00;
    TRISB &= ~0x0F;
    TRISB |= 0xF0;
   
    init_Timers();
   
    while(1);
}

---------------------------------------SOURCE CODE--------------------------------------------

Tuesday, March 22, 2011

Simple Line Following Mobot

A year ago I built a simple line following mobot. It doesn't use any microcontroller(Arduino, PIC, Atmel, etc.) and even logic ICs.

Simplest Line Following Mobot


This line following mobot uses basic electronic components. Actually, the circuit for this mobot is based on the previous project light/dark activated switch.

The chassis and wheels of the robot are recycled materials. The body is from a box of cookies and the wheels are from the container of wafer stick. I also added a wristband from one of presidential candidates last election for the additional traction of the wheel.

The whole circuit for this mobot is not mounted on a pcb nor a protoboard but on a mini-breadboard. I also uses scrap components for this mobot I found on my bin. 
 

The circuit on the mini-breadboard

This is the circuit of the simple line following mobot.


Basic components are used in this mobot. I uses the following components(all in pairs): bright leds, resistor, variable resistor, ldr, general purpose npn transistor, signal diode, spdt relay and a geared dc motor. 

Here are some pictures of the mobot parts:


Top view of the mobot



DC Geared Motor with recycled wheels.


Sensor part: pair of LEDs and LDRs.


Powered up!


Isometric view of the robot

This is a simple demo video showing the performance of the mobot:




Monday, February 7, 2011

Quiz Bee Buzzer Circuit using PIC16f628a

This is a simple simulation on implementing a Quiz Bee Buzzer using a PIC microcontroller. 




*source code to be followed..