PDA

View Full Version : [Question(s)] HELP!!! How to send command to SSC-32 from ATmega 32 using CodeVision



gonzo
01-04-2011, 12:34 PM
:sad:
Hi , I'm gonzo.

I just bought a phoenix hexapod, but have some issue in connecting my ATMega 32 to SSC 32
(I use atmel because I'm more familiar with them).

I'm using CodeVision AVR with C language (but sometimes AVR Studio also)

I can't send my command to SSC. I've connected the AVR's TX to SSC RX and connect the ground.
I also has set the baud rate to 9600.

Nothing happened.

Can anyone help me please ( I guess my problem is in the code)

Thanks

DresnerRobotics
01-04-2011, 01:00 PM
Perhaps posting some code would help us better understand your problem. Simply plugging the SSC-32 into an AVR doesn't make it work.

gonzo
01-04-2011, 01:31 PM
Hi Tyberius

Here is the code I'm using:


/************************************************** ***
This program was produced by the
CodeWizardAVR V1.25.3 Professional
Automatic Program Generator
© Copyright 1998-2007 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date : 1/3/2011
Author : F4CG
Company : F4CG
Comments:


Chip type : ATmega32
Program type : Application
Clock frequency : 16.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 512



************************************************** ***/

#include <mega32.h>
#include <delay.h>

// Standard Input/Output functions
#include <stdio.h>

// Declare your global variables here
#define channel 0
#define position 1000
#define time 750
#define ASCII_CR 13

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x67;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
while (1)
{

// Place your code here
putsf("#");
putchar(channel);
putsf("P");
putchar(position);
putsf("T");
putchar(time);
putchar(ASCII_CR);
delay_ms(500);
};
}


Please help, I'm stuck for 3 days thinking about it

Upgrayd
01-04-2011, 03:54 PM
If you wanted to send the command "#0 P1000 T750" to the ssc-32 then each character in that string needs to be sent separately.

gonzo
01-04-2011, 06:45 PM
cAN anyone show some code example?
Thanks:happy:confused:

lnxfergy
01-04-2011, 07:08 PM
// Declare your global variables here
#define channel 0
#define position 1000
#define time 750
#define ASCII_CR 13
// Place your code here
putsf("#");
putchar(channel);
putsf("P");
putchar(position);
putsf("T");
putchar(time);
putchar(ASCII_CR);


The issue here is ascii vs. decimal. The SSC-32 expects ascii strings, you're sending decimal values (which are also exceeding the 8-bit limit for a character).

To print channel, you need to convert 0 into ascii 0 -- putchar(channel + 48)

To print position & time, you'll need to convert them into multiple ascii values:
putchar(time/100 + 48); // 7 + 48
putchar((time%100)/10 + 48); // 5 + 48
putchar((time%10) + 48); // 0 + 48

-Fergs

gonzo
01-04-2011, 08:08 PM
The issue here is ascii vs. decimal. The SSC-32 expects ascii strings, you're sending decimal values (which are also exceeding the 8-bit limit for a character).

To print channel, you need to convert 0 into ascii 0 -- putchar(channel + 48)

To print position & time, you'll need to convert them into multiple ascii values:
putchar(time/100 + 48); // 7 + 48
putchar((time%100)/10 + 48); // 5 + 48
putchar((time%10) + 48); // 0 + 48

-Fergs

Hi Fergs, here is the code that I use (#P1000T750cr)

It can be compiled with no error.

But still nothing happened, and the SSC-32 led doesn't blink too.

#define channel 0
#define position 1000
#define time 750
#define ASCII_CR 13
..........
while(1)
{
putchar(35);
putchar(48);// Channel 0
putchar(80);
putchar(position/1000 + 48); // 1 + 48
putchar((position%10) + 48); // 0 + 48
putchar((position%10) + 48); // 0 + 48
putchar((position%10) + 48); // 0 + 48
putchar(84);
putchar(time/100 + 48); // 7 + 48
putchar((time%100)/10 + 48); // 5 + 48
putchar((time%10) + 48); // 0 + 48
putchar(ASCII_CR);
};
}

gonzo
01-04-2011, 08:19 PM
Wooo..
I'm getting really confused :confused:

I don't know what's wrong!
The connection seems right:

TX atmega (PORTD1) to RX SSC-32

RX atmega not connected (uni direction communication)

SSC32 has been set to 9600 baudrate .

What's wrong ????

jRaskell
01-05-2011, 01:43 PM
Commands like puts() and putchar() send their output to the stdout stream. While the AVR library does provide definitions for the standard streams, none of the are initialized to any specific output by default.

In effect, your code is sending your serial commands nowhere at all. You have to write code to send the data out the serial port yourself.

Once that code is written, you could alternately pipe your puts/putchar calls to it as well, but there's really no advantage to doing so, and you'll only incur additional code overhead for your command calls.

The atmega datasheets provide some concise samples for setting up and using the USART. I pulled this code out of the atmega168 datasheet. I do not know if this will also work on the atmega32. You should check that datasheet for sample code first.


void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRnA & (1<<UDREn)) )
;
/* Put data into buffer, sends the data */
UDRn = data;
}

KurtEck
01-05-2011, 03:17 PM
Quickly looking through the code, I agree with the others.
1) You need to send all of the characters as an ASCII stream. That is to output Channel 0 you need to output an ASCII "0", not a binary zero.
2) Need to make sure the the Ascii_CR is sending the right character (most likely is)
3) Need to direct the output from puts to the hardware port.

In addition to this, make sure the jumpers are set properly on the SSC-32 to be 9600 baud.

FYI - I have ported the Phoenix code to run on Atmega 1280s (Arduino Mega). Both using the Arduino code as well as using another library Webbotlib. Most of these sources can be found in the Lynxmotion forums.

Good Luck
Kurt

gonzo
01-06-2011, 12:36 PM
SOLVED...!!!!

HURRAH!!

The problem comes from the microcontroller I use. (it's already broken):p

Btw, for CodeVision you don't need to convert the alphabet and position,also time value to ASCII .

All you have to do is just:

//Below is pieces of code I use

#define channel 0
#define position 1000
#define time 2000

putchar("#%uP%uT%u",channel,position,time);
delay_ms(2000); // Delay provides time for the command to execute

Thanks a lot for all your help and advice.:happy: