Search Forums by tag:
Serial, mbed, compiler, ethernet, USB, I2C, SPI, interrupt, LCD, library, bug, HTTPServer, CAN, AnalogIn, adc, Power, Ticker, memory, pwm, SD Card, InterruptIn, rpc, Error, SDFileSystem, PwmOut, LocalFileSystem, UART, canbus, TCP, driver, interrupts, rtos, led, libraries, editor, timer, accelerometer, GPS, file, clock, website, LPC11U24, C++, SD, frequency, reset, http, flash, SDCard, RTC, DigitalIn, TCPSocket, problem, printf, Java, Servo, buffer, UDP, SerialPC, MODSERIAL, DMA, HTTPClient, Sleep, audio, pinball, NetServices, socket, LPC1768, array, compile, filesystem, RFID, beta, m3pi, voltage, write, JTAG, multiple, newbie, keyboard, sensor, GPRS, Forum, digitalOut, assembly, debug, hardware, Speed, xbee, AnalogOut, RPCFunction, EthernetNetIf, Download, code, wait, network, C, suggestion, binary, keil, MATLAB, offline, Board, lwip, I2S, dead, Nokia6610, time, bluetooth, WiFly, current, tcp/ip, MODDMA, SPI Slave, pololu, robot, Communication, read, dac, string, pc, PCB, filter, copy, USB Host, publish, rs232, DHCP, Host, Data Logging, windows, firmware, malloc, mp3, gcc, attach, program, fatfilesystem, class, email, arduino, stepper motor, WavePlayer, wifi, Nokia, camera, size, VGA, import, documentation, ide, linux, baud, TextLCD, Cortex-M0, M0, pointers, pullup, Relay, timing, function, latency, serial port, MIDI, compiler error codes, magjack, touch, screen, Production, client, server, stream, HID, breakout, FIFO, prototype, flashing, GPIO, sampling, Analog, display, api, ADXL345, Encoder, DSP, help, motor, sram, suggestions, PING, Terminal, link, browser, Pin, control, Eagle, Modbus, EEPROM, mac, Timeout, fopen, port, updates, usbserial, batteries, DMX, files, USBMIDI, scanf, protocol, PPP, slave, FTP, integer, noise, MODGPS, modem, float, threads, supply, motors, for, PID, monitor, Digital I/O, 7, Windows Serial Driver, pins, keypad, FAT, classes, webserver, delay, variables, time-triggered, c programming, labview, watchdog, post, math, Battery, LPCXpresso, MBED website, GSM, storage, nxp, mobileLCD, license, int, counter, baseboard, Assembler, Vin, rj45, registers, E289, news, i2cmaster, amoled, Compiling, connect, revision, prototype to hardware, UMTSStick, Optocoupler, Robotics, search, oscillator, glitch, Websockets, load, find, real-time, routine, format, offline compile, powersource, driverlibrary, processing, networking, ID, umts, debugging, color, BUTTON, software, PS3, Images, wave, bin, const, SNMP, OSX, peripheral, sensors, data, Design, version, RIT, character, freeze, USBDevice, bus, ARM, wav, SRF08, heap, output, basic, TFT, QVGA, mysql, piezo, update, ID12, Pachube, player, DigitalInOut, object, cmsis, capture, IR, slow, 1768, PSP, OS, syntax, mbed.lib, EmbeddedArtists, NMEA, paste, project, Web, GUI, UART0, firefox, SQL, wakeup, RAM, bitmap, handler, security, 3D, bugs, OLED, Temperature, not, I/O, Bidirectional, rss, wireless, delete, resolved, Input, LED1, LIS302, getc, Safari, Wi-Fi, wiki, PinNames, accounts, PS2, BusOut, projects, RS485, pythonIf config is a one off, then I'd bit bash SPI For that frame, But if it is more frequent, then I think you can actuality Have a FOUR bit SPI frame ?
So you would send 4 bit frame, toggle pin, send 12 bit frame.
Will look at data sheet a little later, just to make sure.
Ceri
If it is fig. 7, then. This is 16 bit packets, Therefore, a pulse afterwards should be OK. Have a look for TLC9540, In the cool book ? It is amazingly similar.
Ceri
You mean the TLC5940? I did but its only 12 bit. I am using this to drive servos. Ok, so a 4 bit packet should work, how do I know that the SPI library sends the most significant bit first? Also which "mode" of SPI do I need to use with this? My guess is "mode 0"...
Thanks again for taking the time to help me.
Regards, Kartik
Ceri, What do you mean by bit bashing the SPI? Yes the configuration is a one off thing in the beginning of the program. Although in the data sheet fig. 6 shows that the LE needs to go high at the 6th or 7th bit all the way to the 16th bit then low.
CS = 0 Data = 1 Clock = 1 Clock = 0 .... .... ..... .... Le = 1 Data ... Clock... Clock ..... .... .... .... Le = 0 Ce = 1
You simply toggle the bits manual, You could put it in a loop, in a subroutine.
So this is what I did and still a no go.
#include "mbed.h"
PwmOut pwclk (p21);
DigitalOut mosi (p5);
DigitalOut le (p6);
DigitalOut clk (p7);
unsigned short servo_pos [16] = {0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF};
unsigned short config = 0xFAAF;
void servo_init (unsigned short config);
void servo_write (unsigned short servo_pos []);
int main()
{
le = 0;
clk = 0;
mosi = 0;
LPC_PWM1->TCR = (1 << 1); // Reset counter, disable PWM
LPC_SC->PCLKSEL0 &= ~(0x3 << 12);
LPC_SC->PCLKSEL0 |= (1 << 12); // Set peripheral clock divider to /1, i.e. system clock
LPC_PWM1->MR0 = 29; // Match Register 0 is shared period counter for all PWM1
LPC_PWM1->MR6 = 14; // Pin 21 is PWM output 6, so Match Register 6
LPC_PWM1->LER |= 1; // Start updating at next period start
LPC_PWM1->TCR = (1 << 0) || (1 << 3); // Enable counter and PWM
servo_init (config);
while (1)
{
servo_write (servo_pos);
}
}
void servo_init (unsigned short config)
{
clk = 0;
for (int i = 0; i < 16; i++)
{
clk = 0;
if (i >= 6 && i < 16)
le = 1;
else
le = 0;
if (config & 0x8000)
mosi = 1;
else
mosi = 0;
config = config << 1;
clk = 1;
}
le = 0;
}
void servo_write (unsigned short servo_pos [])
{
unsigned int byte = 0;
le = 0;
clk = 0;
for (int k = 15; k >= 0; k--)
{
byte = servo_pos [k];
for (int i = 0; i < 16; i++)
{
clk = 0;
if (byte & 0x8000)
mosi = 1;
else
mosi = 0;
byte = byte << 1;
clk = 1;
}
}
le = 1;
le = 0;
}
Alright... everything is solved and working correctly. Thanks for your help!
#include "mbed.h"
PwmOut pwclk (p21);
DigitalOut mosi (p5);
DigitalOut le (p6);
DigitalOut clk (p7);
unsigned short servo_pos [16] = {60620, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF};
unsigned short config = 0xFAAF;
void servo_init (unsigned short config);
void servo_write (unsigned short servo_pos []);
int main()
{
le = 0;
clk = 0;
mosi = 0;
LPC_PWM1->TCR = (1 << 1); // Reset counter, disable PWM
LPC_SC->PCLKSEL0 &= ~(0x3 << 12);
LPC_SC->PCLKSEL0 |= (1 << 12); // Set peripheral clock divider to /1, i.e. system clock
LPC_PWM1->MR0 = 29; // Match Register 0 is shared period counter for all PWM1
LPC_PWM1->MR6 = 14; // Pin 21 is PWM output 6, so Match Register 6
LPC_PWM1->LER |= 1; // Start updating at next period start
LPC_PWM1->TCR = (1 << 0) || (1 << 3); // Enable counter and PWM
servo_init (config);
while (1)
{
servo_write (servo_pos);
}
}
void servo_init (unsigned short config)
{
clk = 0;
for (int i = 0; i < 16; i++)
{
clk = 0;
mosi = 0;
if (i >= 5 && i < 16)
le = 1;
else
le = 0;
if (config & 0x8000)
mosi = 1;
else
mosi = 0;
config = config << 1;
clk = 1;
}
mosi = 0;
clk = 0;
le = 0;
}
void servo_write (unsigned short servo_pos [])
{
unsigned int byte = 0;
le = 0;
clk = 0;
for (int k = 15; k >= 0; k--)
{
byte = servo_pos [k];
for (int i = 0; i < 16; i++)
{
clk = 0;
mosi = 0;
if (k == 0 && i >= 13)
le = 1;
else
le = 0;
if (byte & 0x8000)
mosi = 1;
else
mosi = 0;
byte = byte << 1;
clk = 1;
}
}
mosi = 0;
clk = 0;
le = 0;
}
Please log in to post a reply.
No tags
|
Hi there,
I am trying to interface to this 16 bit LED driver from ST ( http://www.st.com/internet/analog/product/215262.jsp ). It interfaces via SPI but the problem is that to send configuration data to it I need to have one of its pins high for a certain number of bits (yes, bits...). I am not sure how to do that with the current SPI library and I can't seem to find another way. Please refer to page 14 of the data sheet ( http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00237442.pdf ) to gain further understanding of what I mean... Any insight on this would be greatly appreciated.
Regards, Kartik