Author Topic: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK  (Read 100463 times)

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #60 on: September 10, 2010, 11:06:40 AM »
Here's my-first-task.c as it stands now.
Code: [Select]
#include "config.h" // include all headers in case a new file
#include "application_lcd.h"                                             // {46} LCD tests
#include "../../hardware/LPC23XX/spi_acc_lpc_AIS226_2.h"                                          // AIS226 accelerometer

extern void fnMyFirstTask(TTASKTABLE *ptrTaskTable)
{
//vars
static int iState = 0;
int y_high = 0;
int y_low = 0;
int y_now = 0;

// init some stuff
GLCD_TEXT_POSITION text_pos;
GLCD_RECT_BLINK rectjah;

// setup some task stuff / initialize code based on task state
if (!iState) {
// LCD PWM to dim.
fnSetLCDContrast();

// print something to LCD
text_pos.ucMode = PAINT_LIGHT;
text_pos.usX = 2;
text_pos.usY = 40;
text_pos.ucFont = (FONT_FIVE_DOT);
// an ack is requested when this has been completely displayed
text_pos.ucMode = (REDRAW | GIVE_ACK);                   
fnDoLCD_text(&text_pos, "my first task sais hellow");

// print blinking LCD heart beat indicator box
text_pos.usX = 2;
text_pos.usY = 0;
text_pos.ucFont = FONT_NINE_DOT;
rectjah.ucMode = BLINKING_OBJECT;
rectjah.rect_corners.usX_start = 120;
rectjah.rect_corners.usY_start = 120;
rectjah.rect_corners.usX_end = 125;
rectjah.rect_corners.usY_end = 125;
rectjah.blink_half_period = (DELAY_LIMIT)(0.3*SEC);
fnDoLCD_rect(&rectjah);

//config the SPI for the AIS226
fnConfigSPI_AIS226();

// set starting points for min and max indicators
y_high = fnSPI_AIS226(OUTY_L, SPI_READ, 0x00);
y_high = y_high + (fnSPI_AIS226(OUTY_H, SPI_READ, 0x00) << 8);
y_low = y_high;

fnLCD_display_hex(95,100,"high Y",y_high);
fnLCD_display_hex(85,100,"",(y_high >> 8));
// fnLCD_display_hex(85,110,"",(y_low >> 8));
// fnLCD_display_hex(95,110,"low Y",y_low);

iState = 1;
}

// read acceleration and display on screen
//fnLCD_display_hex(95,50,"hex X",fnSPI_AIS226(OUTX_L, SPI_READ, 0x00));
//fnLCD_display_hex(85,50,"",fnSPI_AIS226(OUTX_H, SPI_READ, 0x00));
y_now = fnSPI_AIS226(OUTY_L, SPI_READ, 0x00);
y_now = y_now + (fnSPI_AIS226(OUTY_H, SPI_READ, 0x00) << 8);
if (y_now > y_high) y_high = y_now;
if (y_now < y_low) y_low = y_now;

fnLCD_display_hex(95,60,"high Y",y_high);
fnLCD_display_hex(85,60,"",(y_high >> 8));
fnLCD_display_hex(95,70,"now Y",y_now);
// fnLCD_display_hex(85,70,"",(y_now >> 8));
// fnLCD_display_hex(95,80,"low Y",y_low);
// fnLCD_display_hex(85,80,"",(y_now >> 8));
//fnLCD_display_hex(85,60,"",yh_high);

//fnLCD_display_hex(85,70,"",fnSPI_AIS226(STATUS_REG, SPI_READ, 0x00));

//fnLCD_display_bits(95,50,"PCLKSEL0",*(unsigned long *)0xE01FC1A8 >> 4);// >> 0&0xE0020000);
}
I have modified TaskConfig.h like this
Code: [Select]
#if defined SUPPORT_LCD
  { "LCD",       fnLCD,          LARGE_QUE/*MEDIUM_QUE*/,  (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO), 0, UTASKER_STOP},  //
#elif defined SUPPORT_GLCD || defined SUPPORT_OLED || defined SUPPORT_TFT || defined GLCD_COLOR // {2}{4}
    #ifdef GLCD_COLOR
  { "LCD",       fnLCD,          LARGE_QUE/*SMALL_QUEUE*/, (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO), 0, UTASKER_ACTIVATE}, // runs immediately
    #else
  { "LCD",       fnLCD,          (LARGE_QUE + 128),  (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO), 0, UTASKER_STOP}, // large queue for queuing text
    #endif
The above code is grey, but appears to be compiled. Here's spi_acc_lpc_AIS226_2.h
Code: [Select]
//prototypes
int fnSPI_AIS226(int, int, int);

//defines
#define SET_AIS226_CS_LOW()      _CLEARBITS(0, PORT0_BIT6) // assert the CS line of the AIS226
#define SET_AIS226_CS_HIGH()     _SETBITS(0, PORT0_BIT6)   // negate the CS line of the AIS226

#define WHO_AM_I   0x0F //memory location 0x0F should read as 0x3A
#define STATUS_REG 0x27
#define CTRL_REG1  0x20
#define OUTX_L    0x28
#define OUTX_H     0x29
#define OUTY_L    0x2A
#define OUTY_H     0x2B
#define SPI_READ   0x80 //memory location 0x0F should read as 0x3A
#define SPI_WRITE  0x00 //memory location 0x0F should read as 0x3A


static void fnConfigSPI_AIS226(void)//
{
//pg 436 setup
    POWER_UP(PCSSP1); // power up the SPI on SSP port
//clock note, PCLK_SEL0 select PCLK_SPI default is cclk/4, set bits 16:17 (11) for cclk/8
PCLKSEL0 |= PCLK_SSP1_CCLK_8;// set for /8
    CONFIGURE_SPI_PINS(); //SET PINSEL0 BITS to make pins SPI
    CONFIGURE_CS_LINES(); //FIO0SET and FIO0DIR for software driven CS line
//PINMODE0 |= PINMODE_NO_PULLS_6;//PINMODE_PULLDOWN_6;
//PINMODE0 |= PINMODE_NO_PULLS_7;//PINMODE_PULLDOWN_7;
//PINMODE0 |= PINMODE_NO_PULLS_8;// P0.8 is driven by the slave, so don't drive it here
//PINMODE0 |= PINMODE_NO_PULLS_9;//PINMODE_PULLDOWN_9;
//irq's
//NA verified as off

//other setup
    SSPCPSR_X = 16; // set clock prescaler (even prescale 2..254)
    SSPCR0_X = (DSS_8_BIT); //| FRS_MICROWIRE); // set 8 bit words
    SSPCR1_X = SSP_SSE;         // enable

//make sure AIS226 is set to read a value
fnSPI_AIS226(CTRL_REG1, SPI_WRITE, (0xC0 | fnSPI_AIS226(CTRL_REG1, SPI_READ, 0x00)));
}


static void fnLCD_display_bits(int x, int y, const CHAR *LCD_text, unsigned long bits_displayed){
// init some stuff
GLCD_TEXT_POSITION text_pos;// = {PAINT_LIGHT, 2, 0, FONT_NINE_DOT};

// print something to LCD
text_pos.ucMode = PAINT_LIGHT;
text_pos.ucFont = (FONT_FIVE_DOT);

text_pos.usY = y;
text_pos.usX = x;
fnDoLCD_text(&text_pos, LCD_text);

text_pos.usX = x-47;
fnDoLCD_text(&text_pos, "                     ");//clear display area

text_pos.usX = x-10;
if (bits_displayed & 0x0001) fnDoLCD_text(&text_pos, "1");
else fnDoLCD_text(&text_pos, "0");
text_pos.usX = x-15;
if (bits_displayed & 0x0002) fnDoLCD_text(&text_pos, "1");
else fnDoLCD_text(&text_pos, "0");
text_pos.usX = x-20;
if (bits_displayed & 0x0004) fnDoLCD_text(&text_pos, "1");
else fnDoLCD_text(&text_pos, "0");
text_pos.usX = x-25;
if (bits_displayed & 0x0008) fnDoLCD_text(&text_pos, "1");
else fnDoLCD_text(&text_pos, "0");

text_pos.usX = x-32;
if (bits_displayed & 0x0010) fnDoLCD_text(&text_pos, "1");
else fnDoLCD_text(&text_pos, "0");
text_pos.usX = x-37;
if (bits_displayed & 0x0020) fnDoLCD_text(&text_pos, "1");
else fnDoLCD_text(&text_pos, "0");
text_pos.usX = x-42;
if (bits_displayed & 0x0040) fnDoLCD_text(&text_pos, "1");
else fnDoLCD_text(&text_pos, "0");
text_pos.usX = x-47;
if (bits_displayed & 0x0080) fnDoLCD_text(&text_pos, "1");
else fnDoLCD_text(&text_pos, "0");
}


static void fnLCD_display_hex(int x, int y, const CHAR *LCD_text, int hex_displayed){
// init some stuff
GLCD_TEXT_POSITION text_pos;// = {PAINT_LIGHT, 2, 0, FONT_NINE_DOT};
text_pos.ucMode = PAINT_LIGHT;
text_pos.ucFont = (FONT_FIVE_DOT);

text_pos.usY = y;
text_pos.usX = x;
fnDoLCD_text(&text_pos, LCD_text);

text_pos.usX = x-20;
fnDoLCD_text(&text_pos, "       ");//clear display area

text_pos.usX = x-10;
if (hex_displayed & 0x1) fnDoLCD_text(&text_pos, "1");
else if (hex_displayed & 0x2) fnDoLCD_text(&text_pos, "2");
else if (hex_displayed & 0x3) fnDoLCD_text(&text_pos, "3");
else if (hex_displayed & 0x4) fnDoLCD_text(&text_pos, "4");
else if (hex_displayed & 0x5) fnDoLCD_text(&text_pos, "5");
else if (hex_displayed & 0x6) fnDoLCD_text(&text_pos, "6");
else if (hex_displayed & 0x7) fnDoLCD_text(&text_pos, "7");
else if (hex_displayed & 0x8) fnDoLCD_text(&text_pos, "8");
else if (hex_displayed & 0x9) fnDoLCD_text(&text_pos, "9");
else if (hex_displayed & 0xA) fnDoLCD_text(&text_pos, "A");
else if (hex_displayed & 0xB) fnDoLCD_text(&text_pos, "B");
else if (hex_displayed & 0xC) fnDoLCD_text(&text_pos, "C");
else if (hex_displayed & 0xD) fnDoLCD_text(&text_pos, "D");
else if (hex_displayed & 0xE) fnDoLCD_text(&text_pos, "E");
else if (hex_displayed & 0xF) fnDoLCD_text(&text_pos, "F");
else fnDoLCD_text(&text_pos, "0");

text_pos.usX = x-15;
if (hex_displayed & 0x10) fnDoLCD_text(&text_pos, "1");
else if (hex_displayed & 0x20) fnDoLCD_text(&text_pos, "2");
else if (hex_displayed & 0x30) fnDoLCD_text(&text_pos, "3");
else if (hex_displayed & 0x40) fnDoLCD_text(&text_pos, "4");
else if (hex_displayed & 0x50) fnDoLCD_text(&text_pos, "5");
else if (hex_displayed & 0x60) fnDoLCD_text(&text_pos, "6");
else if (hex_displayed & 0x70) fnDoLCD_text(&text_pos, "7");
else if (hex_displayed & 0x80) fnDoLCD_text(&text_pos, "8");
else if (hex_displayed & 0x90) fnDoLCD_text(&text_pos, "9");
else if (hex_displayed & 0xA0) fnDoLCD_text(&text_pos, "A");
else if (hex_displayed & 0xB0) fnDoLCD_text(&text_pos, "B");
else if (hex_displayed & 0xC0) fnDoLCD_text(&text_pos, "C");
else if (hex_displayed & 0xD0) fnDoLCD_text(&text_pos, "D");
else if (hex_displayed & 0xE0) fnDoLCD_text(&text_pos, "E");
else if (hex_displayed & 0xF0) fnDoLCD_text(&text_pos, "F");
else fnDoLCD_text(&text_pos, "0");
}

static void fnSetLCDContrast(void){
// configure PWM output for contrast control
    TIMER_INTERRUPT_SETUP timer_setup = {0};                             // PWM Timer Init Struct
    timer_setup.int_type = TIMER_INTERRUPT;                              // timer setup type
    timer_setup.int_priority = 0;
    timer_setup.int_handler = 0;                                         // no interrupts used
    timer_setup.timer_reference = PWM1;                                  // use PWM module
    timer_setup.timer_mode  = (TIMER_PWM_6 | PWM_OUTPUT_PORT_1);         // use PWM channel 1 on port 1 output location
    timer_setup.timer_value = TIMER_US_DELAY(TIMER_FREQUENCY_VALUE(200));// 10000 Hz contrast frequency
    timer_setup.pwm_value   = _PWM_PERCENT(27,timer_setup.timer_value);//temp_pars->temp_parameters.ucGLCDContrastPWM, timer_setup.timer_value); // contrast as PWM value
    fnConfigureInterrupt((void *)&timer_setup);   
}


int fnSPI_AIS226(int cmd, int rw, int SPI_data){
unsigned long temp;
int temp2, null;
temp = SSP0CR0; //appears something else uses this SPI reg, so lets save it and restore it when done with this process
SSP0CR0 = (SSP0CR0 & 0xfff0) | 0x07;//clear the lower 4 bits, and set an 8 bit word
SET_AIS226_CS_LOW(); // assert SS low before starting
//FIO0PIN &= 0xffffffbf; // assert SS low before starting

SSPDR_X = (cmd | rw); // send command the 0x80 sets the read vs write bit.
SSPDR_X = SPI_data; // send blank bits to allow clocks for return command
while (!(SSPSR_X & SSP_RNE)){};//first byte is blank
null = SSPDR_X;
while (!(SSPSR_X & SSP_RNE)){};//second byte is the address
temp2 = SSPDR_X;
while (SSPSR_X & (SSP_BSY | SSP_RNE)) {// wait for all transfers to complete and clear rx buffer
    null = SSPDR_X; //save it to ulDummy
    }

SET_AIS226_CS_HIGH(); // assert SS high after done transmission
//FIO0PIN |= 0x00000040; // assert SS high after done transmission
SSP0CR0 = temp; //return to the normally scheduled program.
return temp2;
}
I changed application_LCD.h like this
Code: [Select]
        case TASK_LCD:
            fnRead( PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]); // read the complete message
            if (E_LCD_INITIALISED == ucInputMessage[0]) {
#if !defined SUPPORT_TFT
                GLCD_TEXT_POSITION text_pos;// = {PAINT_LIGHT, 2, 0, FONT_NINE_DOT};
                text_pos.ucMode = PAINT_LIGHT;
                text_pos.usX = 2;
                text_pos.usY = 15;
                text_pos.ucFont = (FONT_FIVE_DOT);
                fnDoLCD_text(&text_pos, "We'll show you how");
                text_pos.usY = 40;
                text_pos.ucFont = (FONT_FIVE_DOT);
                text_pos.ucMode = (REDRAW | GIVE_ACK);                   // an ack is requested when this has been completely displayed
                fnDoLCD_text(&text_pos, "started");
    #endif
            }
            /*else if (E_LCD_READY == ucInputMessage[0]) {                 // an  acknowledgement from the display task (last job has been completed)

blah, blah

}*/
            break;
#endif
I know there are bugs in my-first-task.c. Currently it doesn't display the high and low values as expected. They appear, but appear to be incorrect numbers. It seems to ignore the if statement and always runs y_high = y_now. I believe that issue is separate from the display issues. I think I'm just using the logic operator incorrectly.

I believe I have increased the buffer size in the TaskConfig.h. Also my SPI coms send two bytes, then waits for completion of those two. So I believe it should send a max of 2 out of the 8 deep fifo. Is the 8 fifo shared with the LCD's I2C? I have to confess some ignorance about the details of the fifo.

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #61 on: September 12, 2010, 05:14:04 PM »
The simulator is awesome, and I was surprised at how easy it was to emulated the accelerometer. I did my emulation with this code.
Code: [Select]
SET_AIS226_CS_LOW(); // assert SS low before starting
//FIO0PIN &= 0xffffffbf; // assert SS low before starting

SSPDR_X = (cmd | rw); // send command
SSPDR_X = SPI_data; // send blank bits to allow clocks for return command
while (!(SSPSR_X & SSP_RNE)){//};//first byte is blank
#ifdef _WINDOWS
    SSPSR_X |= SSP_RNE; // SET flag for simulator
#endif
}
null = SSPDR_X;
while (!(SSPSR_X & SSP_RNE)){};//second byte is the returned data
#ifdef _WINDOWS
if (cmd == OUTY_L) SSPDR_X = (unsigned char)fnRandom();// simulate AIS226 data
if (cmd == OUTY_H) SSPDR_X = 0x01;// simulate AIS226 data
#endif
temp2 = SSPDR_X;
while (SSPSR_X & (SSP_BSY | SSP_RNE)) {// wait for all transfers to complete and clear rx buffer
null = SSPDR_X; //save it to ulDummy
#ifdef _WINDOWS
SSPSR_X &= ~SSP_RNE; // CLEAR flag for simulator
SSPSR_X &= ~SSP_BSY; // CLEAR flag for simulator
#endif
    }
SET_AIS226_CS_HIGH(); // assert SS high after done transmission
Now it's going to be a while before I flash the target. Awesome.

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #62 on: September 12, 2010, 09:49:52 PM »
The LCD buffer issue is fixed. Upping the que to (LARGE_QUE + 1024) did it. Now all the printed lines are displaying. I guess that an increase to LARGE_QUE simply wasn't enough.

I started getting data out of the accelerometer, and it's a bit disappoint. The error bracket appears to be about 0xA0 which is higher than expected on a device that claims 14bit resolution. I'll have to look at the accelerometer internal settings and see if I can tune out the noise. I'm back on track and digging deeper into the AIS226.

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #63 on: September 12, 2010, 11:56:09 PM »
That wasn't that hard to tune. I changed the Decimation factor to a sampling rate to 40 Hz, it was 2560 Hz for some reason. That chopped out allot of the noise issues. I now write to it's register making it 40 Hz, so it shouldn't wonder unexpectedly. After about 10 seconds the difference between my min and max readings on x is 0, and on Y it's 2. After about 5 minutes of sitting here, the difference on X is 7 and on Y it's also 7. Seems to wonder a little bit there. Not sure why. It's just sitting here on my desk, perhaps it's picking up some vibrations, it seems fairly solid where it's sitting. I wouldn't expect vibration noise, but on the other hand, 0.25mg/bit isn't much of an acceleration.

Rotating the board around by hand I get a full scale of about 7FF on both axis's. I'm a bit concerned about this wondering, I wonder what's causing it and if it can be minimized some how.

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #64 on: September 13, 2010, 10:36:26 AM »
I let this run last night, for about 8 hrs. This morning it claimed a variation on X of 4 and on Y of 2. Right now just a couple minutes later, it's X of 0xB and Y of 0x10. So it would appear that wondering I was concerned about is just local vibration. If it's this accurate, I would wager a guess that the 4 and 2 variations are also local vibrations. 

Also I did some tests looking to see how accurate it was. I propped up one end of the demo board with a piece of paper, aprox .005 inch thick, and it changed the reading by 1 bit. I used a thicker piece of paper, about .010 inch thick, and it changed by 3 bits. Each time after I removed the paper prop, it came back to the original value.

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #65 on: September 25, 2010, 01:09:19 AM »
I'm still trying to figure out the bits that are coming out of this AIS226 chip. It appears the data is a signed number vs unsigned, and there are some interesting effects of the higher level bits. I'm trying to calculate the accumulated acceleration and display it such that I can look for the over all noise floor. I'm trying to do this with the sprintf command, which recommends using sprintf_s. It compiles and runs with out warning or issue on the simulator, but it won't compile for the target. Here's a snippet from my-task.c

Code: [Select]
#include <stdio.h>

blah blah

sprintf_s(mybuf, 10, "%d",(char *)x_now);
//sprintf(mybuf, "%d",(char *)n);
//mybuf = sprintf("%d",(char *)x_now);
fnDoLCD_text(&text_pos, mybuf);//display
The sprintf_s is line 124. When I compile, I get these messages.
Code: [Select]
arm-none-eabi-gcc -march=armv4t -mlittle-endian -mthumb -mthumb-interwork -Wall -Wstrict-prototypes -I../../uTaskerV1.4 -D _GNU -D _LPC23XX -g -c -Os ../my-first-task.c -o Build/my-first-task.o
../my-first-task.c: In function 'fnMyFirstTask':
../my-first-task.c:127: warning: cast to pointer from integer of different size
../my-first-task.c:21: warning: unused variable 'n'
../my-first-task.c: At top level:
../../../hardware/LPC23XX/spi_acc_lpc_AIS226_2.h:70: warning: 'fnLCD_display_bits' defined but not used
../../../hardware/LPC23XX/spi_acc_lpc_AIS226_2.h:113: warning: 'fnLCD_display_hex' defined but not used
arm-none-eabi-gcc -march=armv4t -mlittle-endian -mthumb -mthumb-interwork -Wall -Wstrict-prototypes -I../../uTaskerV1.4 -D _GNU -D _LPC23XX -g -c -Os ../application.c -o Build/application.o
arm-none-eabi-gcc -march=armv4t -mlittle-endian -mthumb -mthumb-interwork -Wall -Wstrict-prototypes -I../../uTaskerV1.4 -D _GNU -D _LPC23XX -g -c -Os ../debug.c -o Build/debug.o

blah blah

arm-none-eabi-gcc -march=armv4t -mlittle-endian -mthumb -mthumb-interwork -Wall -Wstrict-prototypes -I../../uTaskerV1.4 -D _GNU -D _LPC23XX -g -Os -Wl,-Map=uTaskerV1.4.map --no-gc-sections -nostartfiles -TuTaskerLPC23XX.ld -o uTaskerV1.4.elf Build/my-first-task.o Build/application.o Build/debug.o Build/webInterface.o Build/KeyScan.o Build/LCD.o Build/TFT.o Build/NetworkIndicator.o Build/startup_gnu.o Build/LPC23XX.o Build/GLCD.o Build/MODBUS.o Build/modbus_app.o Build/mass_storage.o Build/eth_drv.o Build/Driver.o Build/uMalloc.o Build/uTasker.o Build/Tty_drv.o Build/iic_drv.o Build/uFile.o Build/Watchdog.o Build/GlobalTimer.o Build/low_power.o Build/Ethernet.o Build/arp.o Build/dhcp.o Build/dns.o Build/ftp.o Build/http.o Build/icmp.o Build/ip_utils.o Build/ip.o Build/pop3.o Build/smtp.o Build/tcp.o Build/telnet.o Build/tftp.o Build/udp.o Build/webutils.o Build/NetBIOS.o
Build/my-first-task.o: In function `fnMyFirstTask':
C:\uTaskerV1.4_LPC_take2\Applications\uTaskerV1.4\GNU_LPC23XX/../my-first-task.c:127: undefined reference to `sprintf_s'
collect2: ld returned 1 exit status
cs-make: *** [uTaskerV1.4.elf] Error 1

I tried to create a prototype for sprintf_s, but it still didn't link correctly and failed to compile. Are there any suggestions on how to get the prototype for sprintf_s to work? I'm not sure why this would be different from the simulator to the target build.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #66 on: September 25, 2010, 02:04:42 AM »
Hi

When simulating, the function sprintf_s() is being taken from VisualStudio's library. When compiling for your target this routine probably doesn't exist (it sounds like a secure function). Try using the standard sprintf() so that the cross compiler's library can supply it.

You may also need to add extra libraries too.

If you don't find a solution you can use the uTasker string functions for output conversion and save needing to add libraries and the potential of code-bloat due to them bringing in other unnecessary stuff with them. See http://www.utasker.com/docs/Code.html - Operating System | String Output and Conversion

Regards

Mark

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #67 on: September 25, 2010, 10:15:55 AM »
I tried sprintf, which recommended using sprintf_s. However, that also flops when used to build the target, and works fine when compiled for the simulator. Here's some messages when using the target build.
Code: [Select]
c:\utaskerv1.4_lpc_take2\applications\utaskerv1.4\my-first-task.c(130) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(366) : see declaration of 'sprintf'
Linking...

blah blah

arm-none-eabi-gcc -march=armv4t -mlittle-endian -mthumb -mthumb-interwork -Wall -Wstrict-prototypes -I../../uTaskerV1.4 -D _GNU -D _LPC23XX -g -Os -Wl,-Map=uTaskerV1.4.map --no-gc-sections -nostartfiles -TuTaskerLPC23XX.ld -o uTaskerV1.4.elf Build/my-first-task.o Build/application.o Build/debug.o Build/webInterface.o Build/KeyScan.o Build/LCD.o Build/TFT.o Build/NetworkIndicator.o Build/startup_gnu.o Build/LPC23XX.o Build/GLCD.o Build/MODBUS.o Build/modbus_app.o Build/mass_storage.o Build/eth_drv.o Build/Driver.o Build/uMalloc.o Build/uTasker.o Build/Tty_drv.o Build/iic_drv.o Build/uFile.o Build/Watchdog.o Build/GlobalTimer.o Build/low_power.o Build/Ethernet.o Build/arp.o Build/dhcp.o Build/dns.o Build/ftp.o Build/http.o Build/icmp.o Build/ip_utils.o Build/ip.o Build/pop3.o Build/smtp.o Build/tcp.o Build/telnet.o Build/tftp.o Build/udp.o Build/webutils.o Build/NetBIOS.o
c:/gccfd/codesourcery-arm-2008q1/bin/../lib/gcc/arm-none-eabi/4.2.3/../../../../arm-none-eabi/bin/ld.exe: section .ARM.exidx [00000000 -> 0000000f] overlaps section .vectors [00000000 -> 0000002f]
c:/gccfd/codesourcery-arm-2008q1/bin/../lib/gcc/arm-none-eabi/4.2.3/../../../../arm-none-eabi/lib/thumb\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text+0xc): undefined reference to `_sbrk'
c:/gccfd/codesourcery-arm-2008q1/bin/../lib/gcc/arm-none-eabi/4.2.3/../../../../arm-none-eabi/lib/thumb\libc.a(lib_a-writer.o): In function `_write_r':
writer.c:(.text+0x10): undefined reference to `_write'

blah blah
I read that as sprintf wasn't well supported because it wants you to use sprintf_s. However sprintf_s has the library/include issue. It seems like sprintf just isn't all that well supported for the target build. Also I like your version because of the bloat thing you mentioned.

Looks like your fnBufferDec() will work for me. Now I just need to get the data from the AIS226 formated into a normal number. One part of the data sheet notes "16 bit internal representation, 14 bit resolution" while another area notes "(0: 12 bit right justified; 1: 16 bit left justified)" So I'm doing some testing to get a feel for if it's 12 bit, 14 bit, ect.

Thanks for the reply, again spot on and I'm back off and running.

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #68 on: September 26, 2010, 04:42:03 PM »
I'm having some trouble with the math.h library. This may be the same issue I had with the stio.h. When compiled for the target, it flops. Perhaps I need a command like -lm for link math library, or similar. I tried adding that to the build process, but no dice. This is the messages I get when I compile for target using a asin function. This also compiles just fine for the simulator.

Code: [Select]
arm-none-eabi-gcc -march=armv4t -mlittle-endian -mthumb -mthumb-interwork -Wall -Wstrict-prototypes -lm -I../../uTaskerV1.4 -D _GNU -D _LPC23XX -g -Os -Wl,-Map=uTaskerV1.4.map --no-gc-sections -nostartfiles -TuTaskerLPC23XX.ld -o uTaskerV1.4.elf Build/my-first-task.o Build/application.o Build/debug.o Build/webInterface.o Build/KeyScan.o Build/LCD.o Build/TFT.o Build/NetworkIndicator.o Build/startup_gnu.o Build/LPC23XX.o Build/GLCD.o Build/MODBUS.o Build/modbus_app.o Build/mass_storage.o Build/eth_drv.o Build/Driver.o Build/uMalloc.o Build/uTasker.o Build/Tty_drv.o Build/iic_drv.o Build/uFile.o Build/Watchdog.o Build/GlobalTimer.o Build/low_power.o Build/Ethernet.o Build/arp.o Build/dhcp.o Build/dns.o Build/ftp.o Build/http.o Build/icmp.o Build/ip_utils.o Build/ip.o Build/pop3.o Build/smtp.o Build/tcp.o Build/telnet.o Build/tftp.o Build/udp.o Build/webutils.o Build/NetBIOS.o
Build/my-first-task.o: In function `fnMyFirstTask':
C:\uTaskerV1.4_LPC_take2\Applications\uTaskerV1.4\GNU_LPC23XX/../my-first-task.c:137: undefined reference to `asin'
collect2: ld returned 1 exit status
cs-make: *** [uTaskerV1.4.elf] Error 1
It appears #include <math.h> isn't working as I would expect. Any suggestions on how to get the math lib included such that it will compile?

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #69 on: September 26, 2010, 06:04:09 PM »
Hi

You will almost certainly need to link a GCC library containing the missing function (and possibly sub-routines to it).
I don't think that this is a compiler issue and also the math.h include is probably OK since the compiler would probably otherwise generate a warning as the function is not prototyped. It looks to be the liker not being able to link the function from a library (adding a prototype of a function via  header will satisfy the compiler but will not allow the linker to work if it can't locate it).

Here it suggests that the function asin() is built-in according to ISO C90 and only specifying -fno-builtin would stop it. Probably this is assuming that the GCC libraries are otherwise being actively linked into the project (?):
http://coen.boisestate.edu/smloo/ece332fall2007/niosdocumentation/gnu-tools/gcc/Other-Builtins.html#Other%20Builtins

See which libraries are included in you GCC version and try to identify where the asin() is situated and then explicitly link that library.

Regards

Mark

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #70 on: September 28, 2010, 11:35:56 AM »
I'm using arm-none-eabi-gcc for the compiler. I believe it was installed via Olimex CD, and used by the default gnu make file that came with utasker. It appears that asin is in libm.a which can be specified with -lm.

http://www.network-theory.co.uk/docs/gccintro/gccintro_17.html
http://www.codesourcery.com/archives/arm-gnu/msg01877.html

I've tried a variety of absolute links and such to ensure it pointed to a specific libm.a. I have 4 under the codesourercy directory. They didn't work. I also wonder how the pre-compiled .a files would know flags like -mthumb, ect. Wouldn't those .a files need to have similar compile fags? I don't have a subscription to codesourercy, so I can't ask them on the forums.

I'm trying to modify the make file and see what happens with the yartago version of the compiler. However that can't find the files for some reason. On the command prompt I've been trying a variety of ../ vs ..\ placed in "s, ect. No luck getting the yartago to compile yet.

I'm still unable to get the .a files to work with either gnu compiler.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #71 on: September 28, 2010, 01:17:08 PM »
Hi

I have never used these libraries so don't have any tips at the moment on what needs to be done.

The libraries can be compiled in ARM or THUMB mode and there may be two versions depending on which is preferred. However ARM and Thumb mode can be mixed (as long as inter-working is defined when compiling) so, even if only one is available (and its build is not known) this shouldn't be a problem.

Good luck with your efforts to get the library linked...

regards

Mark


Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #72 on: September 29, 2010, 01:31:53 PM »
I got it to work, and wanted to share. It appears the -lm needs to be after my-first-task.o. Here's a snippet of my make file.
Code: [Select]
$(CC) $(C_FLAGS)    blah blah     uTaskerV1.4.elf $(OBJS)-lm
$(CC) $(C_FLAGS)    blah blah     uTaskerV1.4_BM.elf $(OBJS) -lm
I would have caught that sooner, but I didn't update it for both the BM and normal version. So the BM version would produce an error message very similar to my normal message. Oops, but I got it figured out.

It now compiles and appears to work with the asin function. Yeah, I'm back to the normally scheduled program.

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #73 on: November 30, 2010, 01:39:19 PM »
I'm now trying to use the dynamic http stuff such that I can stream a bunch of data from the AIS226DS chip. I have been trying to follow the uTaskerV1.4_LPC2XXX.PDF and I'm at the part where I expect to browse to http://10.10.10.3 and get a 404 message. However Chrome reports this.

Error 102 (net::ERR_CONNECTION_REFUSED): Unknown error.

Firefox and IE note the page can't be displayed. When I browse to ftp://10.10.10.3 I get this.

favicon.ico   1150 B   5/1/09 1:00:00 AM

I have tried uploading the pages as noted in the pdf, but I can't get FTP to upload. I have tried LeechFTP, Explorer, and a variety of browsers. They will show it, but what I try to upload I get via leechftp, I get this log.

~ Connected to 10.10.10.3, waiting for response...
< 220 Welcome LPC23XX FTP.
> USER anonymous
< 331 Enter pass.
> PASS *****
< 230 Log OK.
> REST 1
< 500 What?.
> SYST
< 215 UNIX Type: L8
> PWD
< 257 "/"
~ Login completed.
> PORT 10,10,10,10,12,200
< 200 OK.
> TYPE A
< 200 OK.
> LIST
< 150 Data.
< LISTERROR: -r-xr-xr-x 1 502 502 1150 May 1 2009 favicon.ico
< 226 OK.
> NOOP
< 200 OK.
> NOOP
< 200 OK.
> MKD adf
< 500 What?.
> PORT 10,10,10,10,12,219
< 200 OK.
> TYPE A
< 200 OK.
> LIST
< 150 Data.
< LISTERROR: -r-xr-xr-x 1 502 502 1150 May 1 2009 favicon.ico
< 226 OK.

When I try to create a directory with Explorer, it produces a dialog that notes "500 What?".

I have disabled the local software firewall, and I have commented out HTTP_UTFAT and FTP_UTFAT I'm not sure why it doesn't produce the 404 page as expected, and I'm unsure why the FTP is giving me trouble. Are there any suggestions on how to get this web page stuff working?

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #74 on: November 30, 2010, 06:11:58 PM »
Hi

If the HTTP connection is being refusing it sounds as though the HTTP server is not running - otherwise it should return the 404 error (this will work with any browser). I would check that the server is being correctly started (and has enough memory to start - it only needs a small amount from heap - about 70 bytes per session). With wireshark check what the answer to the TCP SYN on the TCP port 80 is - if it as a RST it means that there is no HTTP server listening on that port.

FTP in internal FLASH (without SD card utFAT) doesn't support directories so it is normal that you get a "500 WHAT" back when trying to create one. The same is true for any other non-supported command. A "
Code: [Select]
500 WHAT" is not usually a problem, it is just telling the client that the command is not understood (a "WHAT" is in fact a "WHAT??? - don't known what you mean...". The client then known that it can't command that but this doesn't stop further operation with commands that are supported.

It looks like your main problem is that the FTP client is trying to create a directory called "adf" and, since this is not allowed, it doesn't transfer any files.
With DOS FTP client simply connect and command "PUT file.htm 0.htm" to upload a local file called file.htm (replace with the file to be loaded) to the uFileSystem file 0.htm.
If you use the bat file in the web server directory it will automatically copy each web page using the DOS FTP cleint (just make sure that the fiel contains teh IP address that you are using). This has never failed as far as I know.

Regards

Mark