Menu

Inspiration from Youtube video "Small basic!"

Winch
2022-02-18
2022-04-03
<< < 1 2 3 > >> (Page 2 of 3)
  • Anobium

    Anobium - 2022-02-19

    Are you saying that LED is not turning off or on from the application?

    Connect Terminal to the ttl/usb port. Reset the AVR board. Does the Terminal show the 'Small Basic Responder"? if not, you have not connected the TX between the chip and the USB/TTL

     
  • Winch

    Winch - 2022-02-20

    Indeed the LED does not want to go on or off via the software of the small basic program.

    I'm just worried that my USB/TTL device isn't working properly! In my windows device manager there is also a text that PL2303HXA has been phased out since 2012.
    So in other words I don't trust it! And another thing I also noticed that when I use the serial monitor in Arduino (just like the terminal of GCB) I see the message Com port busy.
    So, all things considered, I'm afraid that we have a problem too. So I'm going to order a new USB/TTL first.

     
  • Winch

    Winch - 2022-02-20

    In the meantime I have also read the text below. What is the difference between serial and serial1?
    Apparently you have to take this into account with the Leonardo! But it's not clear to me what exactly you should do with this.
    https://www.arduino.cc/en/Main/Arduino_BoardLeonardo
    Note that on the Leonardo, the Serial class refers to USB (CDC) communication; for TTL serial on pins 0 and 1, use the Serial1 class.
    Could you tell me what the difference is?

     
    • Anobium

      Anobium - 2022-02-20

      You get a new USB/TTL and I will see if i still have a board.

      The cdc refers to the USB capability. When the bootloader hand over to tje user code the usb ceases to work and the user must handle the USART.

       
  • Winch

    Winch - 2022-03-04

    It took a while, but now I have a new USB to TTL converter. This one works as it should and doesn't have the old problems I had before.
    But I can't get the communication with the Arduino board and thus the ATmega32u4 going.
    It works perfectly with the Arduino uno. So I don't understand what could be wrong with this one?

    Let me explain what I've been doing in the meantime. I have reduced the code as far as possible to just establish communication between PC and board.
    This means that I send a message back to the PC by means of "HserPrint. This code works flawlessly with the Uno but not with the Leonardo. (see the code below)

    #chip mega32u4, 16     'Arduino UNO
    #option Explicit
    
        'USART settings
      #define USART_BAUD_RATE 9600
      #define USART_TX_BLOCKING
    
      HSerPrint "Small BASIC Responder"
    

    At the working Uno I see the message coming in via the Terminal of Great Cow Basic.
    But not at the Leonardo board.

     
  • Anobium

    Anobium - 2022-03-04

    Ummm....

    Try this - two defines to remap the UNO bit to the bits on the mega32u4

    'Make into a comment to use the AVR chipset
    #CHIP mega32u4, 16
    ' #option Explicit
    #DEFINE TXEN TXEN1
    #DEFINE UDRE UDRE1 
        'USART settings
      #define USART_BAUD_RATE 9600
      #define USART_TX_BLOCKING
    
      HSerPrint "Small BASIC Responder"
    
     
  • Winch

    Winch - 2022-03-04

    I do not see any difference. at this time.
    Just to be clear, I'm not currently working with Aduino's bootloader! So I program the chip directly with my Atmel-ICE programmer. So in other words I use the Leonardo board purely as a test board. But it seems to me that this shouldn't matter?

    What is the simplest way to know if I can communicate with the chip properly?
    Can it get any simpler than this? Just to make sure it's not the chip or board?

     
    • Anobium

      Anobium - 2022-03-04

      Can you upload your ASM ? I need to see it.

       
  • Winch

    Winch - 2022-03-04

    See below!

    ;Program compiled by Great Cow BASIC (0.99.01 2022-01-27 (Windows 64 bit) : Build 1073) for Microchip MPASM
    ;Need help? See the GCBASIC forums at http://sourceforge.net/projects/gcbasic/forums,
    ;check the documentation or email w_cholmondeley at users dot sourceforge dot net.
    
    ;********************************************************************************
    
    ;Chip Model: MEGA32U4
    ;Assembler header file
    .INCLUDE "m32u4def.inc"
    
    ;SREG bit names (for AVR Assembler compatibility, GCBASIC uses different names)
    #define C 0
    #define H 5
    #define I 7
    #define N 2
    #define S 4
    #define T 6
    #define V 3
    #define Z 1
    
    ;********************************************************************************
    
    ;Set aside memory locations for variables
    .EQU  COMPORT=278
    .EQU  PRINTLEN=279
    .EQU  RXEN=280
    .EQU  SERDATA=281
    .EQU  STRINGPOINTER=282
    .EQU  SYSPRINTDATAHANDLER=283
    .EQU  SYSPRINTDATAHANDLER_H=284
    .EQU  SYSPRINTTEMP=285
    .EQU  SYSSTRINGPARAM1=256
    
    ;********************************************************************************
    
    ;Register variables
    .DEF  SYSBITTEST=r5
    .DEF  SYSBYTETEMPA=r22
    .DEF  SYSBYTETEMPB=r28
    .DEF  SYSBYTETEMPX=r0
    .DEF  SYSCALCTEMPA=r22
    .DEF  SYSCALCTEMPX=r0
    .DEF  SYSREADA=r30
    .DEF  SYSREADA_H=r31
    .DEF  SYSSTRINGA=r26
    .DEF  SYSSTRINGA_H=r27
    .DEF  SYSSTRINGB=r28
    .DEF  SYSSTRINGB_H=r29
    .DEF  SYSSTRINGLENGTH=r25
    .DEF  SYSVALUECOPY=r21
    .DEF  SYSTEMP1=r1
    .DEF  SYSTEMP2=r2
    .DEF  SYSTEMP3=r3
    .DEF  SYSTEMP4=r16
    
    ;********************************************************************************
    
    ;Vectors
    ;Interrupt vectors
    .ORG  0
      rjmp  BASPROGRAMSTART ;Reset
    .ORG  2
      reti  ;INT0
    .ORG  4
      reti  ;INT1
    .ORG  6
      reti  ;INT2
    .ORG  8
      reti  ;INT3
    .ORG  14
      reti  ;INT6
    .ORG  18
      reti  ;PCINT0
    .ORG  20
      reti  ;USB_GEN
    .ORG  22
      reti  ;USB_COM
    .ORG  24
      reti  ;WDT
    .ORG  32
      reti  ;TIMER1_CAPT
    .ORG  34
      reti  ;TIMER1_COMPA
    .ORG  36
      reti  ;TIMER1_COMPB
    .ORG  38
      reti  ;TIMER1_COMPC
    .ORG  40
      reti  ;TIMER1_OVF
    .ORG  42
      reti  ;TIMER0_COMPA
    .ORG  44
      reti  ;TIMER0_COMPB
    .ORG  46
      reti  ;TIMER0_OVF
    .ORG  48
      reti  ;SPI_STC
    .ORG  50
      reti  ;USART1_RX
    .ORG  52
      reti  ;USART1_UDRE
    .ORG  54
      reti  ;USART1_TX
    .ORG  56
      reti  ;ANALOG_COMP
    .ORG  58
      reti  ;ADC
    .ORG  60
      reti  ;EE_READY
    .ORG  62
      reti  ;TIMER3_CAPT
    .ORG  64
      reti  ;TIMER3_COMPA
    .ORG  66
      reti  ;TIMER3_COMPB
    .ORG  68
      reti  ;TIMER3_COMPC
    .ORG  70
      reti  ;TIMER3_OVF
    .ORG  72
      reti  ;TWI
    .ORG  74
      reti  ;SPM_READY
    .ORG  76
      reti  ;TIMER4_COMPA
    .ORG  78
      reti  ;TIMER4_COMPB
    .ORG  82
      reti  ;TIMER4_OVF
    
    ;********************************************************************************
    
    ;Start of program memory page 0
    .ORG  84
    BASPROGRAMSTART:
    ;Initialise stack
      ldi SysValueCopy,high(RAMEND)
      out SPH, SysValueCopy
      ldi SysValueCopy,low(RAMEND)
      out SPL, SysValueCopy
    ;Call initialisation routines
      rcall INITSYS
      rcall INITUSART
    
    ;Start of the main program
    ;----- Configuration
    ;#option Explicit
    ;#define TXEN TXEN1
    ;#define UDRE UDRE1
    ;USART settings
    ;#define USART_BAUD_RATE 9600
    ;#define USART_TX_BLOCKING
    ;HSerPrint "Small BASIC Responder"
      ldi SysStringB,low(SYSSTRINGPARAM1)
      ldi SysStringB_H,high(SYSSTRINGPARAM1)
      ldi SysReadA,low(StringTable1<<1)
      ldi SysReadA_H,high(StringTable1<<1)
      rcall SYSREADSTRING
      ldi SysValueCopy,low(SYSSTRINGPARAM1)
      sts SysPRINTDATAHandler,SysValueCopy
      ldi SysValueCopy,high(SYSSTRINGPARAM1)
      sts SysPRINTDATAHandler_H,SysValueCopy
      ldi SysValueCopy,1
      sts COMPORT,SysValueCopy
    ;SYSSTRINGPARAM*1
      rcall HSERPRINT303
    BASPROGRAMEND:
      sleep
      rjmp  BASPROGRAMEND
    
    ;********************************************************************************
    
    ;Overloaded signature: STRING:byte:, Source: usart.h (1467)
    HSERPRINT303:
    ;PrintLen = PrintData(0)
      lds SysStringA,SysPRINTDATAHandler
      lds SysStringA_H,SysPRINTDATAHandler_H
      ld  SysValueCopy,X
      sts PRINTLEN,SysValueCopy
    ;If PrintLen <> 0 then
      lds SysCalcTempA,PRINTLEN
      tst SysCalcTempA
      breq  ENDIF1
    ;Write Data
    ;for SysPrintTemp = 1 to PrintLen
      ldi SysValueCopy,1
      sts SYSPRINTTEMP,SysValueCopy
    SysForLoop1:
    ;HSerSend(PrintData(SysPrintTemp),comport )
      lds SysTemp1,SysPRINTDATAHandler
      lds SysTemp2,SYSPRINTTEMP
      add SysTemp1,SysTemp2
      mov SysStringA,SysTemp1
      lds SysTemp1,SysPRINTDATAHandler_H
      ldi SysTemp4,0
      adc SysTemp1,SysTemp4
      mov SysStringA_H,SysTemp1
      ld  SysValueCopy,X
      sts SERDATA,SysValueCopy
      rcall HSERSEND293
    ;next
    ;#4p Positive value Step Handler in For-next statement
      lds SysTemp2,PRINTLEN
      lds SysTemp3,SYSPRINTTEMP
      sub SysTemp2,SysTemp3
      mov SysTemp1,SysTemp2
      mov SysBYTETempA,SysTemp1
      ldi SysBYTETempB,0
      rcall SYSCOMPEQUAL
      com SysByteTempX
      sbrs  SysByteTempX,0
      rjmp  ENDIF2
    ;Set LoopVar to LoopVar + StepValue where StepValue is a positive value
      lds SysTemp1,SYSPRINTTEMP
      inc SysTemp1
      sts SYSPRINTTEMP,SysTemp1
      rjmp  SysForLoop1
    ;END IF
    ENDIF2:
    SysForLoopEnd1:
    ;End If
    ENDIF1:
    ;CR
      ret
    
    ;********************************************************************************
    
    ;Overloaded signature: BYTE:byte:, Source: usart.h (918)
    HSERSEND293:
    ;AVR USART1 Send
    ;if comport = 1 Then
      lds SysCalcTempA,COMPORT
      cpi SysCalcTempA,1
      brne  ENDIF3
    ;Wait While UDRE = Off
    SysWaitLoop1:
      lds SysBitTest,UCSR1A
      sbrs  SysBitTest,UDRE1
      rjmp  SysWaitLoop1
    ;End If
    ENDIF3:
    ;----------------------------------------------------
      ret
    
    ;********************************************************************************
    
    ;Source: system.h (156)
    INITSYS:
    ;
    ;'Turn off all ports
    ;PORTB = 0
      ldi SysValueCopy,0
      out PORTB,SysValueCopy
    ;PORTC = 0
      ldi SysValueCopy,0
      out PORTC,SysValueCopy
    ;PORTD = 0
      ldi SysValueCopy,0
      out PORTD,SysValueCopy
    ;PORTE = 0
      ldi SysValueCopy,0
      out PORTE,SysValueCopy
    ;PORTF = 0
      ldi SysValueCopy,0
      out PORTF,SysValueCopy
      ret
    
    ;********************************************************************************
    
    ;Source: usart.h (583)
    INITUSART:
    ;Set baud rate
    ;Enable TX and RX
    ;RXEN = On
      ldi SysValueCopy,1
      sts RXEN,SysValueCopy
    ;TXEN = On
      lds SysValueCopy,UCSR1B
      sbr SysValueCopy,1<<TXEN1
      sts UCSR1B,SysValueCopy
      ret
    
    ;********************************************************************************
    
    ;Source: system.h (2997)
    SYSCOMPEQUAL:
    ;Dim SysByteTempA, SysByteTempB, SysByteTempX as byte
    ;clr SysByteTempX
      clr SYSBYTETEMPX
    ;cpse SysByteTempA, SysByteTempB
      cpse  SYSBYTETEMPA, SYSBYTETEMPB
    ;return
      ret
    ;com SysByteTempX
      com SYSBYTETEMPX
      ret
    
    ;********************************************************************************
    
    ;Source: system.h (1490)
    SYSREADSTRING:
    ;Dim SysCalcTempA As Byte
    ;Dim SysStringLength As Byte
    ;Dim SysCalcTempX As Byte
    ;Get length
    ;lpm SysCalcTempA, Z+
    ;lpm
      lpm
    ;mov SysCalcTempA, SysCalcTempX
      mov SYSCALCTEMPA, SYSCALCTEMPX
    ;SysReadA += 1
      inc SYSREADA
      brne  PC + 2
      inc SYSREADA_H
    ;st Y+, SysCalcTempA
      st  Y+, SYSCALCTEMPA
    ;rjmp SysStringReadCheck
      rjmp  SYSSTRINGREADCHECK
    SYSREADSTRINGPART:
    ;lpm SysCalcTempA, Z+
    ;lpm
      lpm
    ;mov SysCalcTempA, SysCalcTempX
      mov SYSCALCTEMPA, SYSCALCTEMPX
    ;SysReadA += 1
      inc SYSREADA
      brne  PC + 2
      inc SYSREADA_H
    ;add SysStringLength, SysCalcTempA
      add SYSSTRINGLENGTH, SYSCALCTEMPA
    ;Check length
    SYSSTRINGREADCHECK:
    ;If length is 0, exit
    ;cpi SysCalcTempA, 0
      cpi SYSCALCTEMPA, 0
    ;brne SysStringRead
      brne  SYSSTRINGREAD
    ;ret
      ret
    ;Copy
    SYSSTRINGREAD:
    ;Copy char
    ;lpm SysCalcTempX, Z+
    ;lpm
      lpm
    ;SysReadA += 1
      inc SYSREADA
      brne  PC + 2
      inc SYSREADA_H
    ;st Y+, SysCalcTempX
      st  Y+, SYSCALCTEMPX
    ;dec SysCalcTempA
      dec SYSCALCTEMPA
    ;brne SysStringRead
      brne  SYSSTRINGREAD
      ret
    
    ;********************************************************************************
    
    SysStringTables:
    
    StringTable1:
    .DB 21,83,109,97,108,108,32,66,65,83,73,67,32,82,101,115,112,111,110,100,101,114
    
    
    ;********************************************************************************
    
     
  • Anobium

    Anobium - 2022-03-04

    What are the fuses you are setting?

     
  • Winch

    Winch - 2022-03-04

    Read in from Microchip Studio!

     
  • Anobium

    Anobium - 2022-03-04

    I am no expert on this chip but that looks like 8mHz... and the program is 16mHz

    And, the ASM program is not setting the frequency in INITSYS.

     
  • Winch

    Winch - 2022-03-04

    As far as my knowledge goes, these are the basic settings for an Arduino. So I just kept this one. And from Microchip Studio you have no choice but this 8Mhz setting. Everything above 8Mhz will in principle agree with this setting.

    I'm not an ASM expert either and I'm not sure what exactly you mean by the last comment?

    Now I don't know where to look? What are my options?

     
    • Anobium

      Anobium - 2022-03-04

      OK.

      You need to set the fuses to internal clock OSC RC, and, set the program to 8 MHz.

      That could work, It will use the internal clock.

       
  • Winch

    Winch - 2022-03-04

    I do not understand this? The Arduino board runs at 16 Mhz. That's a fact.
    It cannot be the intention that you change this to the internal clock.
    Then you're going to bring the board down in its capabilities.
    Or am I misunderstanding you now?

     
  • Anobium

    Anobium - 2022-03-04

    Ignore the UNO stuff. This is not a 328p.

    So, write the hex with those fuses and the change to the program. Get the basic working first, then, later figure out ext osc.

     
  • Winch

    Winch - 2022-03-04

    Right now I don't know what I'm doing, and I hate that.
    I'm just doing something and that has no basis.
    I'm afraid it's over my head at the moment.

    I need a little more info to get it right.
    You have the Extended, High and the Low variant and actually the question is what must be there to make it work.

     
  • Anobium

    Anobium - 2022-03-04

    Select the drop down Low Sut CkSel select the Internal OSc RC, slowest time.
    leave everything else as is.

     
  • Winch

    Winch - 2022-03-04

    Just did it but no results.

    I'm going to stop this for now. I'm quite frustrated and don't understand why this has to be so complicated.
    Thank you for your patience I will try again tomorrow.

     
  • Winch

    Winch - 2022-03-04

    Last setting!

     
  • Winch

    Winch - 2022-03-05

    Well you're going to like this!
    I wrote a program in OshenSoft AVR Basic this morning. See the code below. With the following result on the terminal. It's starting to look like something isn't right in GCB. I cannot draw any other conclusion.

    'device ATmega32u4
    
    Define CLOCK_FREQUENCY = 16
    
    Dim i As Byte
    
    UART1_Init 9600
    
    WaitMs 1000
    
    For i = 20 To 0 Step -1
        UART1_Write "Number: ", #i, CrLf
        WaitMs 500
    Next i
    
     
  • Winch

    Winch - 2022-03-05

    And I used this setting for the fuses.
    My previous old settings.

     
    • Anobium

      Anobium - 2022-03-05

      Morning,

      I did say GCB was not setting the OSC or handling Usart corre
      correctly.

      Upload the whole working project. Then, we
      can resolve.

       
  • Anobium

    Anobium - 2022-03-05

    Sorry my error.

    I want all the file in a ZIP from OshenSoft AVR Basic project. All the files in the OshenSoft AVR Basic in one zip.

     
<< < 1 2 3 > >> (Page 2 of 3)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.