How to send string of 32 bits using SPI - 16F1939 - PicBasic Pro


+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2018
    Posts
    1

    Default How to send string of 32 bits using SPI - 16F1939 - PicBasic Pro

    Hi,
    I'm trying to address the DataStar addressable LED's, and they require a number of 32-bit frames to set the various parameters correctly. I'm just trying to address one device at this time.

    Could someone please show me how to send a string of 32 bits via SPI?

    Thanks in advance for your help. I'm really stuck.

    Roy

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,104

    Default Re: How to send string of 32 bits using SPI - 16F1939 - PicBasic Pro

    Maybe something like this will do:

    Code:
    byte1    var byte
    byte2    var byte
    byte3    var byte
    byte4    var byte
    
    shiftout  datapin, clockpin, mode, [byte1, byte2, byte3,byte4]
    Ioannis

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default Re: How to send string of 32 bits using SPI - 16F1939 - PicBasic Pro

    Here is a small test program I wrote a while back.

    '************************************************* **************************
    '* Name : ap102A.pbp *
    '* Author : DAVID PUROLA *
    '* Notice : *
    '* : *
    '* Date : 12/29/2017 *
    '* Version : 1.0 *
    '* Notes : only tested on pic18 @64 MHZ *
    '* : pic18f26k22
    '************************************************* **************************
    DEFINE NO_CLRWDT 1
    DEFINE LOADER_USED 1
    define OSC 64
    OSCCON = %11110000

    SCL VAR PORTC.0
    SDA VAR PORTC.1
    PC2 VAR PORTC.2
    PC3 VAR PORTC.3

    led_num con 143 'number of led's in string

    SCRATCH VAR WORD
    LEDS VAR WORD
    COWSHOME VAR BIT

    ANSELA = 0
    ANSELB = 0
    ANSELC = 0
    trisc=%11010000

    MAIN:

    PC2 = 1
    SHIFTOUT SDA,SCL,1,[0,0,0,0] 'START FRAME
    SCRATCH = (LED_NUM - 1) / 48
    LED:
    SHIFTOUT SDA,SCL,1,[$F0,$FF,$00,$00] 'GLOBAL,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$F0,$10,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$E0,$20,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$D0,$30,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$C0,$40,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$B0,$50,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$A0,$60,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$90,$70,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$80,$80,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$70,$90,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$60,$A0,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$50,$B0,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$40,$C0,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$30,$D0,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$20,$E0,$00] 'GLOBAL,BLUE,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$10,$F0,$00] 'GLOBAL,BLUE,GREEN

    SHIFTOUT SDA,SCL,1,[$F0,$00,$FF,$00] 'GLOBAL,GREEN
    SHIFTOUT SDA,SCL,1,[$F0,$00,$F0,$10] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$E0,$20] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$D0,$30] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$C0,$40] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$B0,$50] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$A0,$60] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$90,$70] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$80,$80] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$70,$90] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$60,$A0] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$50,$B0] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$40,$C0] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$30,$D0] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$20,$E0] 'GLOBAL,GREEN,RED
    SHIFTOUT SDA,SCL,1,[$F0,$00,$10,$F0] 'GLOBAL,GREEN,RED

    SHIFTOUT SDA,SCL,1,[$F0,$00,$00,$FF] 'GLOBAL,RED
    SHIFTOUT SDA,SCL,1,[$F0,$10,$00,$F0] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$20,$00,$E0] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$30,$00,$D0] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$40,$00,$C0] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$50,$00,$B0] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$60,$00,$A0] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$70,$00,$90] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$80,$00,$90] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$90,$00,$70] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$A0,$00,$60] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$B0,$00,$50] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$C0,$00,$40] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$D0,$00,$30] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$E0,$00,$20] 'GLOBAL,RED,BLUE
    SHIFTOUT SDA,SCL,1,[$F0,$F0,$00,$10] 'GLOBAL,RED,BLUE

    SCRATCH = SCRATCH - 1
    IF SCRATCH.15 = 0 THEN LED

    SCRATCH = 8
    EOF:
    SHIFTOUT SDA,SCL,1,[$FF] 'END FRAME
    SCRATCH = SCRATCH - 1
    IF SCRATCH.15 = 0 THEN EOF
    PC2 = 0

    PAUSE 1000

    PC3 = 1
    SHIFTOUT SDA,SCL,1,[0,0,0,0] 'START FRAME
    SCRATCH = (LED_NUM - 1)
    LEDOFF:
    SHIFTOUT SDA,SCL,1,[$F0,$00,$00,$00] 'GLOBAL,OFF
    SCRATCH = SCRATCH - 1
    IF SCRATCH.15 = 0 THEN LEDOFF

    SCRATCH = 8
    EOFOFF:
    SHIFTOUT SDA,SCL,1,[$FF] 'END FRAME
    SCRATCH = SCRATCH - 1
    IF SCRATCH.15 = 0 THEN EOFOFF
    PC3 = 0

    PAUSE 1000

    GOTO MAIN

    stop
    Dave Purola,
    N8NTA
    EN82fn

Similar Threads

  1. Emulating SPI rom with PICbasic pro?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th July 2015, 18:38
  2. How to send a string with another string inside it?
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th May 2011, 17:11
  3. send e-mail with EZL50 and picbasic pro
    By cosmos1966 in forum mel PIC BASIC
    Replies: 0
    Last Post: - 29th January 2009, 14:00
  4. How to send a binary string on an output?
    By Robson in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 25th July 2007, 22:54
  5. How to configure SPI in PICBASIC PRO?
    By moogle in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th April 2007, 18:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts